Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
EZEK
Starting Member
8 Posts |
Posted - 2008-01-28 : 11:39:38
|
| hi guys im having some problems with arrays as parameterwhat i want to do is pass a array of comma separated values i.e 12,24,36 and use the in(@parameter) but it doesnt worki've found some solutions, like ALTER PROCEDURE [dbo].[GetLawyers] ( @LawyerTypeIDs VARCHAR(100)ASDECLARE @SQL VARCHAR(2000)SET @SQL = 'SELECT * FROM [dbo].[TB_VALOR_BANCOS] WHERE [PARCELAS] IN (' + @LawyerTypeIDs + ')'EXECUTE (@SQL)but in my case doesnt work.here is a part of my codeSELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY cod_banco ORDER BY coeficiente asc) AS RecID FROM tb_valor_bancoswhere (1 = CASE WHEN @TABELA IS NULL THEN 1 ELSE CASE WHEN TABELA = @TABELA THEN 1 ELSE 0 END END )AND (1 = CASE WHEN @PARCELAS IS NULL THEN 1 ELSE CASE WHEN PARCELAS in(@PARCELAS) THEN 1 ELSE 0 END END )...i know there is a way to pass the array into a table but it doesnt work toothanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-28 : 11:50:32
|
http://www.sommarskog.se/arrays-in-sql.html E 12°55'05.25"N 56°04'39.16" |
 |
|
|
EZEK
Starting Member
8 Posts |
Posted - 2008-01-28 : 12:04:01
|
| i use SQL SERVER 2005 and i think it does not acceptCREATE FUNCTION fixstring_single(@str nvarchar(MAX), @itemlen tinyint)RETURNS TABLE ASRETURN(SELECT listpos = n.Number,<--error str = substring(@str, @itemlen * (n.Number - 1) + 1, @itemlen) FROM Numbers n WHERE n.Number <= len(@str) / @itemlen + CASE len(@str) % @itemlen WHEN 0 THEN 0 ELSE 1 END)errorMsg 208, Level 16, State 1, Procedure fixstring_single, Line 3Invalid object name 'Numbers'. |
 |
|
|
EZEK
Starting Member
8 Posts |
Posted - 2008-01-28 : 13:59:37
|
| thx i used the function with inner join and worked |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-29 : 04:06:45
|
quote: Originally posted by EZEK i use SQL SERVER 2005 and i think it does not acceptCREATE FUNCTION fixstring_single(@str nvarchar(MAX), @itemlen tinyint)RETURNS TABLE ASRETURN(SELECT listpos = n.Number,<--error str = substring(@str, @itemlen * (n.Number - 1) + 1, @itemlen) FROM Numbers n WHERE n.Number <= len(@str) / @itemlen + CASE len(@str) % @itemlen WHEN 0 THEN 0 ELSE 1 END)errorMsg 208, Level 16, State 1, Procedure fixstring_single, Line 3Invalid object name 'Numbers'.
You should have a Number tableor replace FROM Numbers nwith FROM (select row_number() over (order by s1.name) as number from sysobjects s1 cross join sysobjects s2) as nMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|