Click here to Skip to main content
15,888,610 members
Home / Discussions / Database
   

Database

 
Questionmembers db or table? Pin
Jassim Rahma15-May-11 2:13
Jassim Rahma15-May-11 2:13 
AnswerRe: members db or table? Pin
dasblinkenlight15-May-11 22:54
dasblinkenlight15-May-11 22:54 
GeneralRe: members db or table? Pin
Jassim Rahma16-May-11 3:41
Jassim Rahma16-May-11 3:41 
GeneralRe: members db or table? Pin
dasblinkenlight16-May-11 3:50
dasblinkenlight16-May-11 3:50 
GeneralRe: members db or table? Pin
Jassim Rahma16-May-11 4:02
Jassim Rahma16-May-11 4:02 
GeneralRe: members db or table? Pin
dasblinkenlight16-May-11 4:10
dasblinkenlight16-May-11 4:10 
AnswerRe: members db or table? Pin
Shameel17-May-11 4:34
professionalShameel17-May-11 4:34 
QuestionUsing a variable table [modified] Pin
MAW3014-May-11 9:28
MAW3014-May-11 9:28 
I am trying to read table data from all my tables in a database to a summary table which contains the table anme in a column, but I am not sure what is the best way to go about doing this. Should I use temp tables or sp_executesql or some other method. I want to use a variable for the table name but I don't think that will work unless I split the string below in 2 and insert a table name. Or should I use temp tables which I am not familiar with or other method, if so how would I do that.

I appreciate any help I can get.
Thanks in advance,
Michael


SET @SQLString1 = N'
DECLARE
@dtLatestDate DATETIME
SELECT @dtLatestDate = B.dtDateTime
FROM
(
SELECT TOP (1) dtDateTime
FROM '

(split here the add tablename, see below)
@TableName

SET @SQLString2 = N'
ORDER BY dtDateTime DESC
) AS B'



OPEN strTableName_cursor;
FETCH NEXT FROM strTableName_cursor INTO @strTableName;
WHILE @@FETCH_STATUS = 0
BEGIN

EXEC sp_executesql @SQLString1 + @TableName + @SQLString2
UPDATE [dbo].[Summary] SET dtLatestDate = @dtLatestDate WHERE strTableName = @strTableName

FETCH NEXT FROM strTableName_cursor INTO @strTableName
END
CLOSE strSymbol_cursor

modified on Saturday, May 14, 2011 3:50 PM

AnswerRe: Using a variable table Pin
jschell14-May-11 11:39
jschell14-May-11 11:39 
QuestionDynamic column based on row Pin
Ramkumar_S13-May-11 23:26
Ramkumar_S13-May-11 23:26 
AnswerRe: Dynamic column based on row Pin
dasblinkenlight15-May-11 22:47
dasblinkenlight15-May-11 22:47 
QuestionMySql Foreign key referencing Pin
sajid.salim.khan13-May-11 21:39
sajid.salim.khan13-May-11 21:39 
AnswerRe: MySql Foreign key referencing Pin
Shameel17-May-11 4:38
professionalShameel17-May-11 4:38 
QuestionMySql Foreign key Pin
sajid.salim.khan13-May-11 21:24
sajid.salim.khan13-May-11 21:24 
AnswerRe: MySql Foreign key Pin
jschell14-May-11 11:42
jschell14-May-11 11:42 
QuestionSql Server Fetching Data Pin
Ravi_2112-May-11 22:28
Ravi_2112-May-11 22:28 
AnswerRe: Sql Server Fetching Data Pin
Groulien12-May-11 22:40
Groulien12-May-11 22:40 
AnswerRe: Sql Server Fetching Data Pin
Simon_Whale13-May-11 0:41
Simon_Whale13-May-11 0:41 
AnswerRe: Sql Server Fetching Data Pin
SilimSayo13-May-11 3:22
SilimSayo13-May-11 3:22 
AnswerRe: Sql Server Fetching Data Pin
jschell13-May-11 9:03
jschell13-May-11 9:03 
AnswerRe: Sql Server Fetching Data Pin
Shameel17-May-11 4:41
professionalShameel17-May-11 4:41 
QuestionDuplicate a record Pin
solomon1300012-May-11 4:28
solomon1300012-May-11 4:28 
AnswerRe: Duplicate a record Pin
SilimSayo12-May-11 8:38
SilimSayo12-May-11 8:38 
QuestionView Pin
Dhyanga12-May-11 3:50
Dhyanga12-May-11 3:50 
AnswerRe: View Pin
Blue_Boy12-May-11 4:26
Blue_Boy12-May-11 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.