Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

sql server variable

how can i give a value to x

x = 1
INSERT INTO information(
SELECT
(SELECT productid from products where productid = x ),
(select accessoryorder from accessorytypes where accessoryid  = x ),
(SELECT orderid from orders where orderid = x )
select * from information



Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'SELECT'.
Avatar of Aneesh
Aneesh
Flag of Canada image

SET @X = 1
make sure you declare that variable before you use that

declare @x int
set @x = 1
Avatar of rgb192

ASKER

SET @X = 1

Msg 137, Level 15, State 1, Line 1
Must declare the scalar variable "@X".
Avatar of rgb192

ASKER

declare
set

were successful

but

INSERT INTO information(
SELECT
(SELECT productid from products where productid = x ),
(select accessoryorder from accessorytypes where accessoryid  = x ),
(SELECT orderid from orders where orderid = x )



Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'SELECT'.
INSERT INTO information
SELECT
(SELECT productid from products where productid = x ),
(select accessoryorder from accessorytypes where accessoryid  = x ),
(SELECT orderid from orders where orderid = x )
Avatar of rgb192

ASKER

tried both Z and x


INSERT INTO information
SELECT
(SELECT productid from products where productid = Z ),
(select accessoryorder from accessorytypes where accessoryid  = Z ),
(SELECT orderid from orders where orderid = Z )
select * from information

Msg 207, Level 16, State 1, Line 3
Invalid column name 'Z'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Z'.
Msg 207, Level 16, State 1, Line 5
Invalid column name 'Z'.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

works