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 |
|
qutesanju
Posting Yak Master
193 Posts |
Posted - 2009-06-05 : 07:10:04
|
| here i m inserting count dynamically from one table to result tablecreate Procedure GetCount(@LastRunDate as varchar(100))ASbegin-----------------------------------------------------------------------------------------Declare @LastRunDate as varchar(100)--temp table containing source table names and their corrosponding field namesIF OBJECT_ID(N'tempdb..#Count_MasterTBL', N'U') IS NOT NULL DROP TABLE #Count_MasterTBLCREATE TABLE #Count_MasterTBL (Table_Name VARCHAR(100), Date_Col_Name VARCHAR(100), Data_Processed_Date DATETIME ) delete from #Count_MasterTBL Insert into #Count_MasterTBL values('table1','PRODU_DATE_DT1', getdate())Insert into #Count_MasterTBL values('table2','PRODU_DATE_DT2', getdate())Insert into #Count_MasterTBL values('table3','PRODU_DATE_DT3', getdate())--select * from #Count_MasterTBLcreate table #Count_ResultTBL(Table_Name VARCHAR(100), Date_Col_Name VARCHAR(100), Record_Count int , Data_Processed_Date DATETIME ) ----------------------------------------------------------------------------------------------Declare @SQL VarChar(1000)Declare @RowCount intDECLARE @GetRowCount CURSORSET @GetRowCount = CURSOR FOR SELECT * FROM #Count_MasterTBL order by Table_NameOPEN @GetRowCountFETCH NEXTFROM @GetRowCount INTO @RowCountWHILE @@FETCH_STATUS = 0BEGINSELECT @SQL ='SELECT * FROM ' + @GetRowCount.Table_Name + ' where ' + @GetRowCount.Date_Col_Name <= '+ QUOTENAME(CONVERT(VARCHAR(20), @LastRunDate, 121), ''')print @SQL--Exec ( @SQL)insert into #Count_ResultTBL(Table_Name , Date_Col_Name, Record_Count , Data_Processed_Date) VALUES (Table_Name, Date_Col_Name, @RowCount, getdate() )ENDCLOSE @GetRowCountDEALLOCATE @GetRowCountselect * from #Count_ResultTBLend---------------------------------can anybody what's wrong...i m doing. |
|
|
qutesanju
Posting Yak Master
193 Posts |
Posted - 2009-06-05 : 07:29:36
|
| :) |
 |
|
|
qutesanju
Posting Yak Master
193 Posts |
Posted - 2009-06-05 : 08:20:56
|
| pls help |
 |
|
|
|
|
|
|
|