Showing posts with label complete. Show all posts
Showing posts with label complete. Show all posts

Friday, March 9, 2012

reference for error handling

Hi guys,
Do you have complete reference for sql error numbers?
I want to design customize error message, I want to know how to RAISERROR
with correct error number. thanksHi
select * from master.dbo.sysmessages
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Britney" <britneychen_2001@.yahoo.com> wrote in message
news:#abp4FQIFHA.2476@.TK2MSFTNGP12.phx.gbl...
> Hi guys,
> Do you have complete reference for sql error numbers?
> I want to design customize error message, I want to know how to RAISERROR
> with correct error number. thanks
>
>|||Between this and BOL you should be able to figure it all out:
SELECT *
FROM master..sysmessages
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Britney" <britneychen_2001@.yahoo.com> wrote in message
news:%23abp4FQIFHA.2476@.TK2MSFTNGP12.phx.gbl...
> Hi guys,
> Do you have complete reference for sql error numbers?
> I want to design customize error message, I want to know how to RAISERROR
> with correct error number. thanks
>
>|||I tried a test, In this case, table4 doesn't exist in database,
but how can I print out this error ? I want to set this error to a
variable,
maybe to store in in error log table later on.
CREATE PROCEDURE testme
AS
select * from table4
return @.@.error
declare @.errornumber int
exec @.errornumber = testme
print @.errornumber
result:
Server: Msg 208, Level 16, State 1, Procedure testme, Line 3
Invalid object name 'table4'.
"Mike Epprecht (SQL MVP)" <mike@.epprecht.net> wrote in message
news:%23XSu5KQIFHA.3332@.TK2MSFTNGP14.phx.gbl...
> Hi
> select * from master.dbo.sysmessages
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Britney" <britneychen_2001@.yahoo.com> wrote in message
> news:#abp4FQIFHA.2476@.TK2MSFTNGP12.phx.gbl...
RAISERROR
>|||Britney,
Please read Erland Sommarskog's article on error handling so you can get a
handle on batch abortion and other niceties of SQL Server error handling...
http://www.sommarskog.se/error-handling-I.html
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Britney" <britneychen_2001@.yahoo.com> wrote in message
news:exLi5RQIFHA.2476@.TK2MSFTNGP12.phx.gbl...
> I tried a test, In this case, table4 doesn't exist in database,
> but how can I print out this error ? I want to set this error to a
> variable,
> maybe to store in in error log table later on.
>
> CREATE PROCEDURE testme
> AS
> select * from table4
> return @.@.error
> declare @.errornumber int
> exec @.errornumber = testme
> print @.errornumber
> --
> result:
> Server: Msg 208, Level 16, State 1, Procedure testme, Line 3
> Invalid object name 'table4'.
>
> "Mike Epprecht (SQL MVP)" <mike@.epprecht.net> wrote in message
> news:%23XSu5KQIFHA.3332@.TK2MSFTNGP14.phx.gbl...
> RAISERROR
>|||I don't think I can set severity 16 error number to a variable.
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:OVFeyUQIFHA.2476@.TK2MSFTNGP12.phx.gbl...
> Britney,
> Please read Erland Sommarskog's article on error handling so you can get a
> handle on batch abortion and other niceties of SQL Server error
handling...
> http://www.sommarskog.se/error-handling-I.html
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Britney" <britneychen_2001@.yahoo.com> wrote in message
> news:exLi5RQIFHA.2476@.TK2MSFTNGP12.phx.gbl...
>

Saturday, February 25, 2012

Reducing like returned data

I am working on a personal project and am drawing a complete blank
(too much celebrating last night?) on the SQL term that is used to
eliminate multiples of like data when it is returned from the
database.

ie, instead of ...
red
blue
red
green

it would return ...
red
blue
green

Sorry for the trouble and thanks.DISTINCT or GROUP BY will do that for you.

Example:

SELECT DISTINCT colour
FROM ColourTable

--
David Portas
----
Please reply only to the newsgroup
--|||Thanks, David!

On Thu, 1 Jan 2004 23:47:08 -0000, "David Portas"
<REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote:

>DISTINCT or GROUP BY will do that for you.
>Example:
>SELECT DISTINCT colour
> FROM ColourTable
>--
>David Portas
>----
>Please reply only to the newsgroup