Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
MY table is id , errortype,errordescriptionCREATE 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 ASBEGIN 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 ASBEGIN 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 ENDend
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?