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 2005 Forums
 Transact-SQL (2005)
 stored procedure help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-05-17 : 08:44:22
MY table is id , errortype,errordescription
CREATE TABLE [dbo].[errors](
[id] [int] IDENTITY(1,1) NOT NULL,
[errortype] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[errordescription] [nvarchar](250) COLLATE Latin1_General_CI_AS NULL,
[codeerrordescription] [nvarchar](250) COLLATE Latin1_General_CI_AS NULL,
[datetime] [datetime] NULL CONSTRAINT [DF_errors_datetime] DEFAULT (getdate())
) ON [PRIMARY]

How can I do my query below and if there are resuts then I want to concatenate the results into one list listing the error type and error description.
can someone help me with this?


CREATE PROCEDURE checkerrors

AS
BEGIN

select count(id) from errors where datetime>=dateadd(n,-20,getdate())

end

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-17 : 09:18:53
do you mean this?

CREATE PROCEDURE checkerrors

AS
BEGIN

IF EXISTS(select 1
from errors
where datetime>=dateadd(n,-20,getdate()))
BEGIN
DECLARE @ErrorList varchar(max)
SELECT @ErrorList=COALESCE(@ErrorList,'')+ 'ErrorType: ' + [errortype] + ' ErrorDescription: ' + [errordescription] + ','
FROM errors
WHERE datetime>=dateadd(n,-20,getdate())
SELECT @ErrorList
END

end
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-05-17 : 09:25:30
yes thanks - how can I add a line break between lines?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-17 : 09:27:37
use CHAR(13) + CHAR(10)
Go to Top of Page
   

- Advertisement -