|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to load a list of Integer into temp table by SPhi, i have a sp and one of the input parameters is a list of integer,
i.e. '2181440,2183149,21221111'. how can i convert it into temp table at sp? create table #table1 ( AccountCode int ) Use Anith's example
SELECT IDENTITY(INT) "n" INTO Numbers FROM sysobjects s1 CROSS JOIN sysobjects s2 GO create table #table1 ( AccountCode int ) DECLARE @Ids VARCHAR(200) SET @Ids = '5,33,229,1,22' INSERT INTO #table1 SELECT SUBSTRING(@Ids, n, CHARINDEX(',', @Ids + ',', n) - n) from numbers where substring(','+@Ids,n,1)=',' AND n < LEN(@Ids) + 1 drop table Numbers SELECT * FROM #table1 drop table Numbers Show quote "mullin" <mullin***@gmail.com> wrote in message news:1154608067.778146.325460@i42g2000cwa.googlegroups.com... > hi, i have a sp and one of the input parameters is a list of integer, > i.e. '2181440,2183149,21221111'. > > how can i convert it into temp table at sp? > > create table #table1 ( > AccountCode int > ) > See http://www.sommarskog.se/arrays-in-sql.html for some techniques.
-- Show quoteHope this helps. Dan Guzman SQL Server MVP "mullin" <mullin***@gmail.com> wrote in message news:1154608067.778146.325460@i42g2000cwa.googlegroups.com... > hi, i have a sp and one of the input parameters is a list of integer, > i.e. '2181440,2183149,21221111'. > > how can i convert it into temp table at sp? > > create table #table1 ( > AccountCode int > ) > You can split strings in a stored proc. Rough example:
if @string is not null begin select * into #temp from split(@string,',') end You can also do an insert directly into a table of your choice instead of a temp table. -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************* Think Outside the Box! ************************************************* "mullin" <mullin***@gmail.com> wrote in message news:1154608067.778146.325460@i42g2000cwa.googlegroups.com... > hi, i have a sp and one of the input parameters is a list of integer, > i.e. '2181440,2183149,21221111'. > > how can i convert it into temp table at sp? > > create table #table1 ( > AccountCode int > ) > Split of T-SQL ? Are you sure?
Show quote "msnews.microsoft.com" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message news:eS2sTmvtGHA.4336@TK2MSFTNGP06.phx.gbl... > You can split strings in a stored proc. Rough example: > > if @string is not null > begin > select * into #temp from split(@string,',') > end > > You can also do an insert directly into a table of your choice instead of > a temp table. > > -- > Gregory A. Beamer > MVP; MCP: +I, SE, SD, DBA > > ************************************************* > Think Outside the Box! > ************************************************* > "mullin" <mullin***@gmail.com> wrote in message > news:1154608067.778146.325460@i42g2000cwa.googlegroups.com... >> hi, i have a sp and one of the input parameters is a list of integer, >> i.e. '2181440,2183149,21221111'. >> >> how can i convert it into temp table at sp? >> >> create table #table1 ( >> AccountCode int >> ) >> > > mullin wrote:
> hi, i have a sp and one of the input parameters is a list of integer, One method:> i.e. '2181440,2183149,21221111'. > > how can i convert it into temp table at sp? > > create table #table1 ( > AccountCode int > ) > http://realsqlguy.com/twiki/bin/view/RealSQLGuy/ParseDelimitedStringToTable |
|||||||||||||||||||||||