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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select query help

Author  Topic 

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2006-06-05 : 23:25:16
hi,
i have a select query..

SELECT @id = JBO_JOB_OPPORTUNITY_ID
FROM OPPORTUNITIES where JBO_TITLE = 'title'

how can i get the each value of @id?. pass it to another variableand then i have to print it.

ex. set @idprint =(@idprint +','+ (CAST(@id as varchar))

print @idprint

output
-----
1, 2, 3
----



khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-05 : 23:38:58
Is this what you want ?
SELECT @id = ''
SELECT @id = @id + JBO_JOB_OPPORTUNITY_ID
FROM OPPORTUNITIES
WHERE JBO_TITLE = 'title'



KH

Go to Top of Page

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2006-06-05 : 23:52:19
how about putting comma in every id, @id is numeric and not varchar
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-05 : 23:56:56
sorry.. missed out that point

SELECT @id = ''
SELECT @id = @id + convert(varchar(10), JBO_JOB_OPPORTUNITY_ID) + ','
FROM OPPORTUNITIES
WHERE JBO_TITLE = 'title'
select @id = left(@id, len(@id) - 1)



KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-06 : 00:10:02
quote:
Originally posted by sign_seventh

how about putting comma in every id, @id is numeric and not varchar



You mean JBO_JOB_OPPORTUNITY_ID is numeric not varchar ?


KH

Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-06 : 01:06:53
Try this one
Declare @tit varchar(100)
Declare @cnt int
Select @cnt =1
While (SELECT count(*) FROM OPPORTUNITIES where JBO_TITLE = 'title') >= @cnt
Begin
SELECT @id = JBO_JOB_OPPORTUNITY_ID
FROM OPPORTUNITIES where JBO_TITLE = 'title'
set @idprint =(@idprint +','+ (CAST(@id as varchar))
Select @cnt = @cnt+1
End


Thanks
KK
Go to Top of Page

sign_seventh
Yak Posting Veteran

66 Posts

Posted - 2006-06-06 : 01:30:34
ei guys.. thnxs for d help
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-06 : 03:07:50
Note that if the concatenated string length exceeds 8000 characters, then you may not have full value. Where do you want to show the data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -