Click here to Skip to main content
15,900,258 members
Home / Discussions / Database
   

Database

 
Generalbackup access database Pin
sungsunpark6-Aug-04 5:47
sungsunpark6-Aug-04 5:47 
GeneralRe: backup access database Pin
RichardGrimmer12-Aug-04 1:32
RichardGrimmer12-Aug-04 1:32 
GeneralSearching problem (serious!) Pin
RoyRose786-Aug-04 1:03
RoyRose786-Aug-04 1:03 
GeneralRe: Searching problem (serious!) Pin
Michael Potter6-Aug-04 4:21
Michael Potter6-Aug-04 4:21 
GeneralRe: Searching problem (serious!) Pin
RoyRose786-Aug-04 4:57
RoyRose786-Aug-04 4:57 
GeneralMultiple Conditionals Pin
Peter86753095-Aug-04 8:43
Peter86753095-Aug-04 8:43 
GeneralRe: Multiple Conditionals Pin
Mike Ellison5-Aug-04 13:11
Mike Ellison5-Aug-04 13:11 
GeneralRe: Multiple Conditionals Pin
EdbertP5-Aug-04 13:27
EdbertP5-Aug-04 13:27 
You can try passing a string with the user id's and use it in the WHERE clause of your statement,
e.g.

SELECT *
FROM tblUsers
WHERE UserID IN (SELECT [Value] FROM dbo.Split(<code>@ListOfUserIDs</code>,','))

The code above uses the user defined function Split, which splits a string by the delimiter and converts it into a table.
Below is the user defined function that you can modify as needed.

CREATE FUNCTION dbo.Split
(
	@List nvarchar(2000),
	@SplitOn nvarchar(5)
)  
RETURNS @RtnValue table 
(
		
	Id int identity(1,1),
	Value nvarchar(100)
) 
AS  
BEGIN

	WHILE (CHARINDEX(@SplitOn,@List)>0)
	BEGIN 
	
	INSERT INTO @RtnValue (value)
	SELECT 
	    Value = LTRIM(RTRIM(SUBSTRING(@List,1,CHARINDEX(@SplitOn,@List)-1))) 
	
	   Set @List = SUBSTRING(@List,CHARINDEX(@SplitOn,@List)+LEN(@SplitOn),LEN(@List))
	END
	
	INSERT INTO @RtnValue (Value)
	SELECT Value = LTRIM(RTRIM(@List))
	
	RETURN
END

There is another way using the EXEC statement in your stored procedure to execute the SQL, and you don't need the split function for this. Some users argued about the efficiency and safety of using EXEC statement, but it's up to you to decide.

DECLARE SqlStr varchar(1000)

SET SqlStr = 'SELECT * FROM tblUser WHERE UserID IN (' + @ListOfUserID + ')'
EXEC (SqlStr)

Both code will work even if you only pass one ID.
I hope it helps Wink | ;) .
GeneralRe: Multiple Conditionals Pin
Peter86753099-Aug-04 4:57
Peter86753099-Aug-04 4:57 
GeneralMS SQL 7 Error Pin
payal sheth5-Aug-04 2:51
payal sheth5-Aug-04 2:51 
Generalcomparing memo fields in Access Pin
pankajdaga4-Aug-04 23:47
pankajdaga4-Aug-04 23:47 
GeneralCreating db table from DataTable Pin
matt cole3-Aug-04 2:23
matt cole3-Aug-04 2:23 
GeneralRe: Creating db table from DataTable Pin
Thea Burger3-Aug-04 3:09
Thea Burger3-Aug-04 3:09 
GeneralRe: Creating db table from DataTable Pin
matt cole3-Aug-04 19:08
matt cole3-Aug-04 19:08 
Generalhide relation in parent table Pin
Anonymous2-Aug-04 23:43
Anonymous2-Aug-04 23:43 
Questionhow to connect Oracle Lite Database with ADO.NET ? Pin
manoj_mevada2-Aug-04 22:29
manoj_mevada2-Aug-04 22:29 
GeneralDataReader reading data from multiple tables Pin
abhishk2001@yahoo.com2-Aug-04 15:59
abhishk2001@yahoo.com2-Aug-04 15:59 
GeneralRe: DataReader reading data from multiple tables Pin
iamalik043-Aug-04 1:37
sussiamalik043-Aug-04 1:37 
Generalignore last one, this is the tsql puzzle Pin
partt2-Aug-04 8:43
partt2-Aug-04 8:43 
GeneralRe: ignore last one, this is the tsql puzzle Pin
Steven Campbell2-Aug-04 9:04
Steven Campbell2-Aug-04 9:04 
GeneralRe: ignore last one, this is the tsql puzzle Pin
partt2-Aug-04 9:35
partt2-Aug-04 9:35 
GeneralRe: ignore last one, this is the tsql puzzle Pin
partt2-Aug-04 11:22
partt2-Aug-04 11:22 
GeneralRe: ignore last one, this is the tsql puzzle Pin
Steven Campbell2-Aug-04 14:30
Steven Campbell2-Aug-04 14:30 
GeneralRe: ignore last one, this is the tsql puzzle Pin
partt3-Aug-04 4:00
partt3-Aug-04 4:00 
GeneralRe: ignore last one, this is the tsql puzzle Pin
partt3-Aug-04 5:13
partt3-Aug-04 5:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.