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
 SQL Server Development (2000)
 Transform Data

Author  Topic 

ramdas
Posting Yak Master

181 Posts

Posted - 2003-01-08 : 17:17:42
Hi Folks,
I have query which returns a list of ID's which are not present in a master lookup table. I want to be able report the missing ID's in the following format:
Assume I get results Like
23
4
12
5
I want to return a string like "The iD's 23,4,12,5 are missing...", In short I want to be able to concatenate the missing ID's, how would I achieve this in SQL.

Bye

Ramdas Narayanan
SQL Server DBA

SamC
White Water Yakist

3467 Posts

Posted - 2003-01-08 : 17:51:56
I *think* it will take a stored procedure to get this done.

DECLARE @mystring varchar (8000)
SET @mystring = NULL

select @mystring = IsNull(@mystring + ', ' + ID, ID)
FROM MyTable
WHERE give your condition here

The string could be returned as a recordset with

SELECT @mystring

but I'd rather return it as an output parameter. If you need help with OUTPUT parameters, there are some good papers on this website. Use the search option on the home page for 'output parameter'.

HTH

Sam

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-01-08 : 19:44:12
My SQL Wish #323:

A CONCAT() aggregate function.....



- Jeff
Go to Top of Page
   

- Advertisement -