Could do something like:
-- declare local @lookin_columnlist related variables
declare @lookin_columnlist varchar(256) -- table columns to search in
declare @column_find_start int -- start place holder for
@column_find_start listlen
declare @column_find_end int -- start place holder for
@column_find_end listlen
declare @column_delim_char char(1) -- delimiter character
-- continue until the delimiter is not found in @lookin_columnlist
WHILE @column_find_start != 0
BEGIN
-- PRINT @lookin_columnlist -- debug: column list
-- PRINT @column_delim_char -- debug: delimiter
SELECT @column_find_end =
CHARINDEX(@column_delim_char,@lookin_columnlist,@column_find_start+1) --
find the first substring ending position
IF @column_find_end = 0 -- no more items found, then set @column_find_end
SELECT @column_find_end = len(@lookin_columnlist)+1 -- set
@column_find_end to length of @lookin_columnlist to get column item
BEGIN
-- PRINT convert(varchar(4),@column_find_start) + ' to ' +
convert(varchar(4),@column_find_end) -- debug: substring start to end values
PRINT substring(@lookin_columnlist, @column_find_start,
(@column_find_end-@column_find_start))
SELECT @column_field = substring(@lookin_columnlist, @column_find_start,
(@column_find_end-@column_find_start))
SELECT @keyword_list = @keyword_list + 'event_title like ''%' + @keyword
+ '%'' OR '
SELECT @column_find_start = @column_find_end + 1 -- set the next
starting position to the last substring end postion plus 1
END
-- get additional substring until there are no more list items, set
@column_find_start appropriately
IF @column_find_end !=len(@lookin_columnlist)+1
SELECT @column_find_start = @column_find_end + 1 -- set the next
starting position to the last substring end postion plus 1
ELSE
SELECT @column_find_start = 0 -- leave at zero (0) to stop the loop
END
Orlando
-----Original Message-----
From: Colin Robinson [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 20, 2001 7:26 AM
To: SQL
Subject: Using Lists
Is there a way to loop through a list in T-SQL?
I would like to pass a list of user ids to a sp and then update records
based upon that list.
the code I am trying to replace woul be something like this:
<cfloop list="#attributes.user_id#" index="user">
<cfquery datasource="mline">
UPDATE users
SET user_enabled =
#iif(evaluate('attributes.user_'&user&'_enabled'),0,1)#
WHERE user_id = #user#
</cfquery>
</cfloop>
TIA
Colin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists