Skip to content

Instantly share code, notes, and snippets.

@peschkaj
Last active November 29, 2015 21:42
Show Gist options
  • Select an option

  • Save peschkaj/06a0f10250bdc1966134 to your computer and use it in GitHub Desktop.

Select an option

Save peschkaj/06a0f10250bdc1966134 to your computer and use it in GitHub Desktop.
CREATE TABLE conversion (
from VARCHAR(50) NOT NULL ,
to VARCHAR(50) NOT NULL ,
conversion_factor DECIMAL (38, 10) NOT NULL
) ;
ALTER TABLE conversion
ADD CONSTRAINT pk_conversion
PRIMARY KEY (from, to) ;
INSERT INTO conversion (from, to, conversion_factor) VALUES ('feet', 'meters', 0.3048);
INSERT INTO conversion (from, to, conversion_factor) VALUES ('meters', 'feet', 3.28084);
DECLARE @meters AS INT = 1.35;
SELECT @meters * conversion_factor AS feet
FROM conversion
WHERE from = 'meters'
AND to = 'feet' ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment