Showing posts with label cause. Show all posts
Showing posts with label cause. Show all posts

Sunday, March 11, 2012

Error in query; "Invalid length parameter passed to the substring function"

Hi
i got errro mess "Invalid length parameter passed to the substring function" from this below. Anyone how can give me a hint what cause this, and how i can solve it? if i remove whats whitin thoose [] it works, i dont use [] in the code :)
colums:
VLF_InfectionDestination is nvarchar 254

SELECT TOP 10 tb_AVVirusLog.VLF_VirusName, COUNT(tb_AVVirusLog.VLF_VirusName) AS number
FROM tb_AVVirusLog INNER JOIN
__CustomerMachines002 ON tb_AVVirusLog.CLF_ComputerName = __CustomerMachines002.FalseName
WHERE (CONVERT(varchar, tb_AVVirusLog.CLF_LogGenerationTime, 120) BETWEEN @.fyear + @.fmonth + @.fday AND @.tyear + @.tmonth + @.tday) AND
(__CustomerMachines002.folder_id = @.folderId) [OR
(CONVERT(varchar, tb_AVVirusLog.CLF_LogGenerationTime, 120) BETWEEN @.fyear + @.fmonth + @.fday AND @.tyear + @.tmonth + @.tday) AND
(tb_AVVirusLog.VLF_InfectionDestination LIKE N'%@.%')]
GROUP BY tb_AVVirusLog.VLF_VirusName
HAVING (NOT (tb_AVVirusLog.VLF_VirusName LIKE N'cookie'))
ORDER BY COUNT(tb_AVVirusLog.VLF_VirusName) DESCGenerally, you get this error when you pass in a bad parameter, like a negative startpoint, or a length parameter that takes you out of bounds of the string. Maybe instead of convert (varchar), you should try convert(varchar(10)). I don't see substring in there.|||naa cant get it to work... that damn error pop up no matter what i do...|||is i reverse the order and put in a AND insteed it works... like this
[AND
(CONVERT (tb_AVVirusLog.VLF_InfectionDestination LIKE N'%@.%')] AND (varchar, tb_AVVirusLog.CLF_LogGenerationTime, 120) BETWEEN @.fyear + @.fmonth + @.fday AND @.tyear + @.tmonth + @.tday)]

how come o got that error the other way?

//Mr|||Read the sticky at the top of this forum..Post us the DDL and some sample data and what the expected results are suppose to be...|||How about this?

DECLARE @.date1 datetime, @.date2 datetime
SELECT @.date1 = CONVERT(datetime, @.fyear + @.fmonth + @.fday)
, @.date2 = CONVERT(datetime, @.tyear + @.tmonth + @.tday)

SELECT TOP 10 a.VLF_VirusName
, COUNT(a.VLF_VirusName) AS number
FROM tb_AVVirusLog a
INNER JOIN __CustomerMachines002 b
ON a.CLF_ComputerName = b.FalseName
WHERE ( a.CLF_LogGenerationTime > @.Date1 AND a.CLF_LogGenerationTime <= @.Date2
AND b.folder_id = @.folderId)
OR ( a.CLF_LogGenerationTime > @.Date1 AND a.CLF_LogGenerationTime <= @.Date2
AND a.VLF_InfectionDestination LIKE N'%@.%')
GROUP BY a.VLF_VirusName
HAVING a.VLF_VirusName NOT LIKE N'cookie'
ORDER BY COUNT(a.VLF_VirusName) DESC|||thx, i manage this to work, and i got some new ideas how to do things... :)

//Mr|||thx, i manage this to work, and i got some new ideas how to do things... :)

//Mr

...and you're not gonna share it with us...I'll never gety thos 5 minutes back...

Wednesday, February 15, 2012

Error handling in Stored procedure

I have some DML statements that can cause some errors. I want to handle
them gracefully and go ahead with the rest of the SQL statement. What
is the best approach for this?
Assuming that in a loop I am doing some delete that can cause some
foreign key violation.
Delete from MasterTable --This can cause error if there are child
tables refering to this .
How can I get the error message so that I can log it to a log table?
This is what I am doing
Open a cursor on Tabel List
While
BEGIN
@.DynamicSQL = 'Delete from ' + @.TableName--The tablename wil
change for each iteration
If @.@.Error<>0
Begin
--log error message
END
ELSE
Begin
--log Success message
END
END
I hope I have explained it well.
Thanks in advance> How can I get the error message so that I can log it to a log table?
In the client application. You can only get the error number at the TSQL lev
el, not the error
message. For more information, see the error handling articles at www.sommarskog.s
e.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"SQL novice" <balacr@.gmail.com> wrote in message
news:1132650496.640747.51460@.g14g2000cwa.googlegroups.com...
>I have some DML statements that can cause some errors. I want to handle
> them gracefully and go ahead with the rest of the SQL statement. What
> is the best approach for this?
> Assuming that in a loop I am doing some delete that can cause some
> foreign key violation.
> Delete from MasterTable --This can cause error if there are child
> tables refering to this .
> How can I get the error message so that I can log it to a log table?
> This is what I am doing
> Open a cursor on Tabel List
> While
> BEGIN
> @.DynamicSQL = 'Delete from ' + @.TableName--The tablename wil
> change for each iteration
> If @.@.Error<>0
> Begin
> --log error message
> END
> ELSE
> Begin
> --log Success message
> END
> END
>
> I hope I have explained it well.
> Thanks in advance
>|||Can I somehow force the next iteration to continue when there is some
error.
Here it is throwing the error and coming out when there is some error.
Thanks for your help|||Some type of errors will terminate the batch, most won't. It is all in the a
rticles I referred to.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"SQL novice" <balacr@.gmail.com> wrote in message
news:1132660588.888364.310040@.g47g2000cwa.googlegroups.com...
> Can I somehow force the next iteration to continue when there is some
> error.
> Here it is throwing the error and coming out when there is some error.
> Thanks for your help
>