Click here to Skip to main content
15,886,362 members
Articles / Database Development / SQL Server / SQL Server 2008

Techniques for In-Clause and SQL Server

Rate me:
Please Sign up or sign in to vote.
4.86/5 (14 votes)
15 Feb 2010CPOL19 min read 80K   506   23  
A few ways to work with In-Clause and Stored Procedures with SQL Server and C#.
DECLARE @RC int
DECLARE @InArray varchar(max) ='1,2,3,4,5,6,7,8,9,12345,'
DECLARE @Delimiter varchar(10) = ','
DECLARE @TableName sysname = '#test'
DECLARE @ColumnName sysname = 'id'
declare @JobId uniqueidentifier = NewId()

-- TODO: Set parameter values here.
create table #test
( 
--id varchar(max)
id bigint
)

EXECUTE @RC = [InClause].[dbo].[DelimBigIntListToTable2]
--EXECUTE @RC = [InClause].[dbo].[DelimListToTable2] 
   @InArray
  ,@Delimiter
  ,@TableName
  ,@ColumnName

select * from #test
drop table #test

EXECUTE @RC = [InClause].[dbo].[DelimBigIntListToParm] @List=@InArray, @Delimiter=@Delimiter, @JobId=@JobId

select * from ParmId




DECLARE @RC int
DECLARE @Ids varchar(max) = '1,4,6,7,8,4,33,66,44,55555,65,4,3,4,5,6,76,77,6,5,45,4'

-- TODO: Set parameter values here.

--EXECUTE @RC = [InClause].[dbo].[GetUsingDelimitedParmTable]    @Ids
   
   
EXECUTE @RC = [InClause].[dbo].[GetUsingDelimitedFunctionTable] 
   @Ids
   
GO

truncate table ParmId
truncate table ParmIdWithUniqueBigInt
truncate table UniqueBigInt
truncate table SomeString
--select top 100 * from SomeString

declare @test xml
--set @test = '<L><I>1</I><I>2</I><I>3</I><I>4</I><I>5</I><I>6</I><I>7</I><I>8</I><I>99999</I><I>2</I><I>3</I><I>4</I></L>'

set @test = '<I>1</I><I>2</I><I>3</I>'

select @test.exist('/I[text()[1]  = 2] ')
select @test.query('/I[text()[1]] ')
select T.c.value('.','bigint') as Id 
					from @test.nodes('/I') T(c)


declare @test2 xml
set @test2 = '<I v="1"></I><I v="2"></I>'
select @test2.query('/I/@v')
--select T.c.value('.','bigint') from @test.nodes('/ROOT/ID') T(c)


EXECUTE  [InClause].[dbo].[GetUsingXMLXQuery]
   @test
   
   
  declare @Ids IdsTableType
  insert into @Ids (Id) values(1)
  insert into @Ids (Id) values(2)
  insert into @Ids (Id) values(3)
  insert into @Ids (Id) values(4)
  
  execute GetUsingTypeParm @Ids

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
United States United States
A biography in this little spot...sure.
I've worked at GTE HawaiianTel. I've worked at Nuclear Plants. I've worked at Abbott Labs. I've consulted to Ameritech Cellular. I've consulted to Zurich North America. I've consulted to International Truck and Engine. Right now, I've consulted to Wachovia Securities to help with various projects. I've been to SHCDirect and now at Cision.

During this time, I've used all kinds of tools of the trade. Keeping it to the more familier tools, I've used VB3 to VB.NET, ASP to ASP/JAVASCRIPT/XML to ASP.NET. Currently, I'm developing with C# and ASP.NET. I built reports in Access, Excel, Crystal Reports, and Business Objects (including the Universes and ETLS). Been a DBA on SQL Server 4.2 to 2000 and a DBA for Oracle. I've built OLTP databases and DataMarts. Heck, I've even done Documentum. I've been lucky to have created software for the single user to thousands of concurrent users.

I consider myself fortunate to have met many different people and worked in many environments. It's through these experiences I've learned the most.

Comments and Discussions