Answered by:
How to assign value to a parameter using select query?

Question
-
Hi All,
@Data = Select data from table where dataid=23
Is it possible?
I am getting error ..
Help me how to use the select query in assigning to a parameter.
Thank you
Monday, June 7, 2010 10:21 AM
Answers
-
Hi,
Try this:
DECLARE @Data datatype SET @Data = (Select data from table1 where dataid=23)
Make sure, you get only 1 item from your select statement.
I hope it helps.
J.
There are 10 type of people. Those who understand binary and those who do not.- Edited by Janos BerkeMVP Monday, June 7, 2010 10:35 AM fixed typo
- Proposed as answer by Janos BerkeMVP Monday, June 7, 2010 10:48 AM
- Marked as answer by Ramaraj Kumar Monday, June 7, 2010 12:06 PM
Monday, June 7, 2010 10:33 AM
All replies
-
Hi,
Try this:
DECLARE @Data datatype SET @Data = (Select data from table1 where dataid=23)
Make sure, you get only 1 item from your select statement.
I hope it helps.
J.
There are 10 type of people. Those who understand binary and those who do not.- Edited by Janos BerkeMVP Monday, June 7, 2010 10:35 AM fixed typo
- Proposed as answer by Janos BerkeMVP Monday, June 7, 2010 10:48 AM
- Marked as answer by Ramaraj Kumar Monday, June 7, 2010 12:06 PM
Monday, June 7, 2010 10:33 AM -
Select @data = data from table where dataid=23
NM
- Proposed as answer by Janos BerkeMVP Monday, June 7, 2010 10:48 AM
Monday, June 7, 2010 10:33 AM -
CREATE TABLE Data
(Sno INT IDENTITY(1,1),[Name] VARCHAR(150))
INSERT INTO Data
([Name])
VALUES('Ragu')
DECLARE @Data VARCHAR(50)
SET @Data=(SELECT [Name] FROM Data WHERE Sno=3)
SELECT @Data-----OR-----------
DECLARE @Data VARCHAR(50)
SELECT @Data=[Name] FROM Data WHERE Sno=3
SELECT @DataThanks
Ramesh.M
- Proposed as answer by Janos BerkeMVP Monday, June 7, 2010 10:48 AM
Monday, June 7, 2010 10:42 AM