Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Using Variables
--Sql Server 2014 Express Edition --Batches are separated by 'go' select @@version as 'sql server version' CREATE TABLE Products ( ProductID int, ProductName varchar(255), ProductCategory varchar(255), ProductPrice decimal(10) ) INSERT INTO Products (ProductID, ProductName, ProductCategory, ProductPrice) VALUES (1, 'iPhone X', 'Technology', 1200), (2, 'Nike Vapor Shoes', 'Apparel', 180), (3, 'Ford Focus', 'Automobile', 18500), (4, 'Nissan Altima', 'Automobile', 18500), (5, 'Astros Cap', 'Apparel', 80), (6, 'Barcelona Jersey', 'Apparel', 90), (7, 'Samsung Galaxy', 'Technology', 850), (8, 'Apple Watch', 'Technology', 320) -- Declaring a temporary variable to be used in the following query DECLARE @temp varchar(255) = ' Gadget' -- Selecting all Products with "Technology" as category, and adding the word "Gadget" to the category using the variable SELECT ProductName, ProductCategory + @temp FROM Products WHERE ProductCategory = 'Technology' -- Using @category variable to store the result of a query DECLARE @category varchar(255) SET @category = ( SELECT ProductCategory FROM Products WHERE ProductPrice = (SELECT MIN(ProductPrice) FROM Products) ) SELECT @category
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
FOREIGN KEY
testing-2
check constraint
Lab 4
Solution 4
Rename column name using 'sp_rename' command
joins
TSQL - Globally unique string generator
Negociosj
Jogarao1
Please log in to post a comment.