Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

sql server variable

Posted on 2010-01-05
9
Medium Priority
?
179 Views
Last Modified: 2012-05-08
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'.
0
Comment
Question by:rgb192
  • 5
  • 4
9 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26183465
SET @X = 1
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26183469
make sure you declare that variable before you use that

declare @x int
set @x = 1
0
 
LVL 1

Author Comment

by:rgb192
ID: 26183483
SET @X = 1

Msg 137, Level 15, State 1, Line 1
Must declare the scalar variable "@X".
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:rgb192
ID: 26183500
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'.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26183615
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 )
0
 
LVL 1

Author Comment

by:rgb192
ID: 26183749
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'.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 26183811
can you please provide the entire query next time onwards, its really tough guessing

i think i already answered this but you accepted another solution

declare @x int
set @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
0
 
LVL 1

Author Closing Comment

by:rgb192
ID: 31673104
works
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question