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
 General SQL Server Forums
 New to SQL Server Programming
 Last table created

Author  Topic 

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-06-01 : 09:26:59
Hi guys,

I'm trying to create a process where i select the data from the last created table out and so far i've got this

DECLARE @TableName varchar(100)

SET @TableName = (SELECT TOP 1 NAME FROM sys.tables group by name order by max(create_date) desc)

SELECT * FROM @tablename

but on the last section am i going to need to apply dynamic sql as i've never really had a situation where i've been require to use it so havn't got a clue

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-01 : 09:31:21
yes. You need dynamic SQL to do the job here.

read this first http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-06-01 : 09:49:14
thanks
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-06-01 : 11:05:19
could anyone show me on this example how this would be do, and i can go from there are the link is confusing me on how to do something like this

massive thanks in advance
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-06-01 : 11:18:20
ignore this i've just cracked if, can't for the life of me wonder why i struggle with seeing what was wrong
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-01 : 11:19:07
DECLARE @TableName varchar(100)

SET @TableName = (SELECT TOP 1 NAME FROM sys.tables group by name order by max(create_date) desc)

EXEC('SELECT * FROM '+@tablename)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -