January 28, 2015 at 5:54 am
Hi how can i put multiple values in the variables.
for eg:
Declare @w_man as varchar
set @w_man = ('julial','BEVERLEYB', 'Lucy') and few more names.
I am getting syntax error(,)
January 28, 2015 at 6:05 am
PiyaKaGhar (1/28/2015)
Hi how can i put multiple values in the variables.for eg:
Declare @w_man as varchar
set @w_man = ('julial','BEVERLEYB', 'Lucy') and few more names.
I am getting syntax error(,)
Quick answer, you can't. You could instead use a table variable.
😎
January 28, 2015 at 7:15 am
In addition to Eirikur's response when you declare variables with datatypes that have a size you should ALWAYS define the size. Defining varchar with no size will get the default size. Do you know what that is? Are you 100% certain it will not change in the next release of sql? Are you sure it hasn't changed in various version of sql over the years?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 28, 2015 at 8:19 am
Hi Friends
This worked for me:
Declare @w_man as varchar(50)
set @w_man = 'julial,BEVERLEYB, Lucy'
January 28, 2015 at 8:31 am
PiyaKaGhar (1/28/2015)
Hi FriendsThis worked for me:
Declare @w_man as varchar(50)
set @w_man = 'julial,BEVERLEYB, Lucy'
That is NOT multiple values. It is a single string value that contains some characters and some commas. To deal with this you need to do one of two things. You will either need to use dynamic sql or split this into multiple values.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 28, 2015 at 9:56 am
Depending on how you are trying to use the values the more appropriate variable may be a Table Variable and something like this.
DECLARE @w_man TABLE (
[Name] Varchar(50)
);
INSERT INTO @w_man ([Name])
SELECT 'Julial'
UNION
SELECT 'BEVERLYB'
UNION
SELECT 'Lucy'
James Phillips
Sr. Consultant
Pragmatic Works
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply