rgb192
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'.
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'.
SET @X = 1
make sure you declare that variable before you use that
declare @x int
set @x = 1
declare @x int
set @x = 1
ASKER
SET @X = 1
Msg 137, Level 15, State 1, Line 1
Must declare the scalar variable "@X".
Msg 137, Level 15, State 1, Line 1
Must declare the scalar variable "@X".
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'.
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 )
SELECT
(SELECT productid from products where productid = x ),
(select accessoryorder from accessorytypes where accessoryid = x ),
(SELECT orderid from orders where orderid = x )
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'.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
works