Is it possible to take a parameter that comes into a sproc that looks like
this:
'abc,xyx,ggg,ddd'
and put the elements which are separated by commas into an array?
Or is there any other method to take action on 'abc' and then 'xyx', and so
on.
Thanks,
don
sql 2000 or sql 7.0Hi,
There is no array concept in SQL Server. But there is an alternate way. See
the below URL:-
http://www.sommarskog.se/arrays-in-sql.html
Thanks
HAri
SQL Server MVP
"DonSQL2222" <DonSQL2222@.discussions.microsoft.com> wrote in message
news:259490C8-DABB-4C82-B963-E2B49C77C752@.microsoft.com...
> Is it possible to take a parameter that comes into a sproc that looks like
> this:
> 'abc,xyx,ggg,ddd'
> and put the elements which are separated by commas into an array?
> Or is there any other method to take action on 'abc' and then 'xyx', and
> so
> on.
> Thanks,
> don
> sql 2000 or sql 7.0
>|||> Is it possible to take a parameter that comes into a sproc that looks like
> this:
> 'abc,xyx,ggg,ddd'
> and put the elements which are separated by commas into an array?
SQL Server has absolutely no idea what you mean by array. But you can store
these values separately in a table, quite simply:
http://www.aspfaq.com/2248|||try
declare @.s varchar(1000), @.i int, @.val varchar(100)
select @.s = '123,456,789,000,'
select @.i = charindex(',', @.s, 1)
while @.i > 0
begin
select @.val = substring(@.s, 1, @.i - 1)
print @.val
select @.s = substring(@.s, @.i + 1, len(@.s))
select @.i = charindex(',', @.s, 1)
end
Rakesh
"DonSQL2222" wrote:
> Is it possible to take a parameter that comes into a sproc that looks like
> this:
> 'abc,xyx,ggg,ddd'
> and put the elements which are separated by commas into an array?
> Or is there any other method to take action on 'abc' and then 'xyx', and s
o
> on.
> Thanks,
> don
> sql 2000 or sql 7.0
>|||Thank you!! works perfectly. Just what i was looking for.
Don
"Rakesh" wrote:
> try
> declare @.s varchar(1000), @.i int, @.val varchar(100)
> select @.s = '123,456,789,000,'
> select @.i = charindex(',', @.s, 1)
> while @.i > 0
> begin
> select @.val = substring(@.s, 1, @.i - 1)
> print @.val
> select @.s = substring(@.s, @.i + 1, len(@.s))
> select @.i = charindex(',', @.s, 1)
> end
> Rakesh
> "DonSQL2222" wrote:
>
Showing posts with label separated. Show all posts
Showing posts with label separated. Show all posts
Friday, February 24, 2012
Array manipulation
Hey all
I have a crystal report
I have a field in the database in table "1" that is a clob and stores codes separated by commas (e.g "1,343,4546,57657,67567,767,")
Then I have table "2" that has multiple records with the codes above in separate records
(e.g.
record 1 = 2
record 2 - 343
)
But not all codes are necessarily in table 2
So i want to separate the codes and show the ones that are not in table 2 as opposed to table 1
I created a formula field that has some manipulation
----------------
StringVar suppCodes:={table1.field(clob)};
stringvar array sort;
sort:=split(suppCodes, ",");
stringVar notresponded := "";
stringVar notr = "";
numberVar i ;
for i:=1 to ubound(sort) do(
if {table2.field} <> sort[i] then
notresponded := notresponded + " " + {table2.field}
)
------------------
But it is returning True and not the string notresponded
I want it to show me the string notresponded
Please someone helpSpot the difference:
stringVar notr = "";
stringVar notr := "";|||Didnt work cos I already dont use that var|||OK, then make it return notresponded, e.g.
for i:=1 to ubound(sort) do(
if {table2.field} <> sort[i] then
notresponded := notresponded + " " + {table2.field}
);
notresponded
Note the semicolon after the )
Should still fix the assignment though :)
I have a crystal report
I have a field in the database in table "1" that is a clob and stores codes separated by commas (e.g "1,343,4546,57657,67567,767,")
Then I have table "2" that has multiple records with the codes above in separate records
(e.g.
record 1 = 2
record 2 - 343
)
But not all codes are necessarily in table 2
So i want to separate the codes and show the ones that are not in table 2 as opposed to table 1
I created a formula field that has some manipulation
----------------
StringVar suppCodes:={table1.field(clob)};
stringvar array sort;
sort:=split(suppCodes, ",");
stringVar notresponded := "";
stringVar notr = "";
numberVar i ;
for i:=1 to ubound(sort) do(
if {table2.field} <> sort[i] then
notresponded := notresponded + " " + {table2.field}
)
------------------
But it is returning True and not the string notresponded
I want it to show me the string notresponded
Please someone helpSpot the difference:
stringVar notr = "";
stringVar notr := "";|||Didnt work cos I already dont use that var|||OK, then make it return notresponded, e.g.
for i:=1 to ubound(sort) do(
if {table2.field} <> sort[i] then
notresponded := notresponded + " " + {table2.field}
);
notresponded
Note the semicolon after the )
Should still fix the assignment though :)
Subscribe to:
Posts (Atom)