Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Is this possible in sql server

Author  Topic 

goranzr85
Starting Member

5 Posts

Posted - 2011-04-19 : 07:04:24
is this possible?
create procedure mySP
@param1 int,
@param2 int,
@param3 int
...
declare @br int
declare @value nvarchar(50)
set @br=0
set value=""
while(br<3)
begin
set @value=@value+ @param+'br'// i know that isn't correct sintax
//can do it in some other way?
//if br=1 then do next set @value=@value+ @param1
end

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-19 : 07:14:39
No - you can't reference the parameter name.
you could
select pnum = 1, val = @param1
into #a
union all
select pnum = 2, val = @param2
union all
select pnum = 3, val = @param3

declare @br int
declare @value nvarchar(50)
set @br=0
set @value=""
while @br<3)
begin
select @br = @br + 1
select @value = @value + val + 'br' from #a where pnum = @br
end

but you might as well do
select @value = @param1 + 'br + @param2 + 'br' + @param3 + 'br'
unless you can pass the values as a table variable.

Another option is

select pnum = 1, val = @param1
into #a
union all
select pnum = 2, val = @param2
union all
select pnum = 3, val = @param3

select @value = (
select val + 'br'
from #a
for xml path('')
)


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -