Discussion:
How to Output BIGINT in RAISERROR
(too old to reply)
SQL Learner
2007-06-25 16:19:24 UTC
Permalink
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows

DECLARE @quantity BIGINT
SET @quantity = 1234567890
RAISERROR('Cannot Process Quantity %d', 16, 1, @quantity)

Of course I could cast it to varchar before raising an error, but is
there a direct way?

TIA
SQL Menace
2007-06-25 16:31:45 UTC
Permalink
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA
try an unsigned integer (u)

DECLARE @quantity BIGINT
SET @quantity = 1234567890
RAISERROR('Cannot Process Quantity %u', 16, 1, @quantity)

Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx
Adam Machanic
2007-06-25 16:38:02 UTC
Permalink
Post by SQL Menace
try an unsigned integer (u)
Doesn't work on my end. SQL Server 2005 SP2, x64 Developer Edition.
What are you running on your end? Perhaps this is platform-dependent.
--
Adam Machanic
SQL Server MVP

Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
SQL Menace
2007-06-25 16:45:59 UTC
Permalink
Post by Adam Machanic
Post by SQL Menace
try an unsigned integer (u)
Doesn't work on my end. SQL Server 2005 SP2, x64 Developer Edition.
What are you running on your end? Perhaps this is platform-dependent.
--
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"http://www.apress.com/book/bookDisplay.html?bID=10220
It works on 2000 but not on 2005 or 2008 (I just checked them both,
both are 32 bit editions)


Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx
Adam Machanic
2007-06-25 17:04:03 UTC
Permalink
Post by SQL Menace
It works on 2000 but not on 2005 or 2008 (I just checked them both,
both are 32 bit editions)
Really weird. I wonder if these were disabled on purpose? Does I64x
work for you?
--
Adam Machanic
SQL Server MVP

Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
SQL Menace
2007-06-25 17:13:19 UTC
Permalink
Post by Adam Machanic
Post by SQL Menace
It works on 2000 but not on 2005 or 2008 (I just checked them both,
both are 32 bit editions)
Really weird. I wonder if these were disabled on purpose? Does I64x
work for you?
--
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"http://www.apress.com/book/bookDisplay.html?bID=10220
Yes I64x works on both 2005 and 2008,the output is 499602d2


Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx
Adam Machanic
2007-06-25 16:34:45 UTC
Permalink
I don't think there's a good way to handle this. For some reason, the %ld
format specifier--which should be the correct one to use in this case--does
not work. You can use the %I64x specifier, but that will output the result
in base 16...
--
Adam Machanic
SQL Server MVP

Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA
SQL Learner
2007-06-25 17:03:46 UTC
Permalink
Post by Adam Machanic
I don't think there's a good way to handle this. For some reason, the %ld
format specifier--which should be the correct one to use in this case--does
not work. You can use the %I64x specifier, but that will output the result
in base 16...
--
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"http://www.apress.com/book/bookDisplay.html?bID=10220
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA
Thanks Adam and Denis!

Sorry for not providing the version. It used to work on 2000 but broke
on 2005 x64. Adam, where did you learn about I64x format? My BOL does
not say anything about it.
Adam Machanic
2007-06-25 17:10:50 UTC
Permalink
Post by SQL Learner
Sorry for not providing the version. It used to work on 2000 but broke
on 2005 x64. Adam, where did you learn about I64x format? My BOL does
not say anything about it.
I remembered it from a C++ project I worked on a while ago and just
tried it on a whim. I'm not sure why SQL Server doesn't allow all of the
available C++ specifiers in this context. Very odd...
--
Adam Machanic
SQL Server MVP

Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
Alejandro Mesa
2007-06-25 18:33:01 UTC
Permalink
Try:

declare @bi as bigint

set @bi = 1234567890

raiserror('%I64d', 10, 1, @bi)
go

Check first "Note" in the link.

RAISERROR (Transact-SQL)
http://msdn2.microsoft.com/en-us/library/ms178592.aspx


AMB
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA
Alejandro Mesa
2007-06-25 18:36:00 UTC
Permalink
Sorry, second one.

AMB
Post by Alejandro Mesa
go
Check first "Note" in the link.
RAISERROR (Transact-SQL)
http://msdn2.microsoft.com/en-us/library/ms178592.aspx
AMB
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA
SQL Learner
2007-06-25 18:58:22 UTC
Permalink
On Jun 25, 1:36 pm, Alejandro Mesa
Post by Alejandro Mesa
Sorry, second one.
AMB
Post by Alejandro Mesa
go
Check first "Note" in the link.
RAISERROR (Transact-SQL)
http://msdn2.microsoft.com/en-us/library/ms178592.aspx
AMB
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA
Thanks Alejandro!

BTW I think the following note in online BOL is misleading:
"To convert a value to the Transact-SQL bigint type".
I am converting _from_ a bigint type into a charachter string, not the
other way around.

Adam Machanic
2007-06-25 18:45:00 UTC
Permalink
Excellent, much better than the "x" option I suggested. Does it work in SQL
Server 2000 as well?
--
Adam Machanic
SQL Server MVP

Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
Post by Alejandro Mesa
go
Check first "Note" in the link.
RAISERROR (Transact-SQL)
http://msdn2.microsoft.com/en-us/library/ms178592.aspx
AMB
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA
SQL Menace
2007-06-25 18:50:36 UTC
Permalink
Post by Adam Machanic
Excellent, much better than the "x" option I suggested. Does it work in SQL
Server 2000 as well?
--
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"http://www.apress.com/book/bookDisplay.html?bID=10220
Post by Alejandro Mesa
go
Check first "Note" in the link.
RAISERROR (Transact-SQL)
http://msdn2.microsoft.com/en-us/library/ms178592.aspx
AMB
Post by SQL Learner
I cannot figure out proper format string for a bigint so that I could
directly embed my input parameter in my exception string, as follows
Of course I could cast it to varchar before raising an error, but is
there a direct way?
TIA- Hide quoted text -
- Show quoted text -
Yep it works in 2000 as well

Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx
Loading...