Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

store results in a table Expand / Collapse
Author
Message
Posted Friday, March 22, 2013 6:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:20 AM
Points: 11, Visits: 235
Hi.

Been working on this for awhile. Can anyone help rewrite this (between the /* */) so that the results are stored in a table

insert into tbl_mssql_errorlog_current
exec xp_readerrorlog

/*
;
WITH cte AS
(
SELECT *
FROM lmadmindb..tbl_mssql_errorlog_current
WHERE (text like 'Error:%' OR text like 'Msg %') and text not like '%18456%'
)
SELECT beforeCurrent.*
FROM cte
OUTER APPLY
(
SELECT *
FROM lmadmindb..tbl_mssql_errorlog_current e
WHERE e.logdate = cte.LogDate
) beforeCurrent
*/
Post #1434236
Posted Friday, March 22, 2013 7:35 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:34 PM
Points: 12,923, Visits: 12,342
I think you are asking how to get the results of your select into a table?

If it is a table that doesn't exist you could use select into:

WITH cte AS
(
SELECT *
FROM lmadmindb..tbl_mssql_errorlog_current
WHERE (text like 'Error:%' OR text like 'Msg %') and text not like '%18456%'
)
SELECT beforeCurrent.*
into SomeNewTable
FROM cte
OUTER APPLY
(
SELECT *
FROM lmadmindb..tbl_mssql_errorlog_current e
WHERE e.logdate = cte.LogDate
) beforeCurrent

OR if the table already exists just change it into a insert:

WITH cte AS
(
SELECT *
FROM lmadmindb..tbl_mssql_errorlog_current
WHERE (text like 'Error:%' OR text like 'Msg %') and text not like '%18456%'
)

Insert into SomeTable
SELECT beforeCurrent.*
FROM cte
OUTER APPLY
(
SELECT *
FROM lmadmindb..tbl_mssql_errorlog_current e
WHERE e.logdate = cte.LogDate
) beforeCurrent



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1434268
Posted Friday, March 22, 2013 10:22 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:20 AM
Points: 11, Visits: 235
That was what I needed ... Thanks very much. Karen
Post #1434377
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse