SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


store results in a table


store results in a table

Author
Message
karen_jonesdba
karen_jonesdba
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 280
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
*/
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26307 Visits: 17553
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 Modens 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)
karen_jonesdba
karen_jonesdba
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 280
That was what I needed ... Thanks very much. Karen
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search