Last active
November 29, 2015 21:42
-
-
Save peschkaj/06a0f10250bdc1966134 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INSERT INTO conversion (from, to, conversion_factor) VALUES ('feet', 'meters', 0.3048); | |
| INSERT INTO conversion (from, to, conversion_factor) VALUES ('meters', 'feet', 3.28084); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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