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.
| Author |
Topic |
|
rSyn
Starting Member
5 Posts |
Posted - 2005-02-02 : 03:51:18
|
Hi,is it possible to naming temp table dynamically ?? ie : #t_20050131 it represent the date (20050131) and in the next day it will automically create temp table named #t_20050201 ???Any suggestion will appreciate |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2005-02-02 : 04:03:20
|
| Why?A temp table only lasts for the life of the connection and is dropped when the connection is.What are you trying to do?Andy |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-02 : 04:27:25
|
| Anyway you can try thisdeclare @date varchar(10)declare @sql varchar(100)select @date=convert(decimal ,d )from (Select (ltrim(str(year(getdate()))) + case when len(ltrim(str(month(getdate()))))=1 then '0'+ltrim(str(month(getdate()))) else ltrim(str(month(getdate()))) end + ltrim(str(day(getdate()-1)))) as d) as tset @date= 't_'+@dateset @sql='Create table '+@date+' (n numeric)'print @sqlexec (@sql)Madhivanan |
 |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2005-02-02 : 04:35:37
|
MadhivananInstead of quote: select @date=convert(decimal ,d )from (Select (ltrim(str(year(getdate()))) + case when len(ltrim(str(month(getdate()))))=1 then '0'+ltrim(str(month(getdate()))) else ltrim(str(month(getdate()))) end + ltrim(str(day(getdate()-1)))) as d) as t
Why not just do thisSET @date = CONVERT(varchar(10),DATEADD(dd,-1,GETDATE()),112)PRINT @date20050201AndyEdit: Added quote |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-02 : 05:10:48
|
| Thanks Andy. Yours is so easyMadhivanan |
 |
|
|
rSyn
Starting Member
5 Posts |
Posted - 2005-02-02 : 23:52:57
|
| Thank You.....it's Work |
 |
|
|
|
|
|