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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 debug function

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2009-12-10 : 20:56:36
Hi there
i've a user defined function (it takes string as parameter and returns a table with words) working nicely until i used it on a table where it throwing an error (Invalid length parameter passed to the LEFT or SUBSTRING function.). because am using it on a big table i need to figure what string actually causing this error so that i can check my function to see why its failing, any idea ?

my sql statement
SELECT [datavalue],[probname]
FROM [dbo].[episode]
CROSS APPLY [dbo].[Util_SplitString2Table]([probname],' ')
WHERE ([status] IS NULL OR [status] = 0)
AND ([probname] IS NOT NULL AND [probname] != '')

Cheers

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2009-12-10 : 21:30:20
figured out finally if any one else wants to know. the loop gave me exactly what row throwing the error..

DECLARE c1 CURSOR FAST_FORWARD
FOR SELECT DISTINCT [probname]
FROM [episode]
WHERE ([episode].[status] IS NULL OR [episode].[status] = 0)
AND ([probname] IS NOT NULL AND [probname] != '')

OPEN c1
DECLARE @v VARCHAR(max)
FETCH NEXT FROM c1 INTO @v
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @v
SELECT [datavalue]
FROM [dbo].[Util_SplitString2Table](@v,' ')
FETCH NEXT FROM c1 INTO @v
END
CLOSE c1
DEALLOCATE c1

Cheers
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-10 : 22:51:22
great...thanks for letting us know....

I'm sure we will all benefit from your knowledge


Did the "loop" spit out the user name?




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2009-12-13 : 14:47:34
i was not after the user name but the particular string thats causing the issue. which i found and fixed it.

Cheers
Go to Top of Page
   

- Advertisement -