Thursday, April 28, 2011

25 April 2011 -- Daily Log

1. Dynamic TableName ,Executing inside while loop....
alter proc salessample(@tablename varchar(50),@did varchar(20))
as begin
create table #salesdetail(sno int identity,This_Week_Left float,This_Week_Right float,Last_Week_Left float, Last_Week_Right float, Paid_Left float,Paid_Right float,Paid float)
DECLARE @SQLString NVARCHAR(500),@i int; set @i=1
while(@i < 9) begin
set @SQLString = N'insert into #salesdetail(This_Week_Left,This_Week_Right,Last_Week_Left,Last_Week_Right,Paid_Left,Paid_Right,Paid) Select This_Week_Left,This_Week_Right,Last_Week_Left,Last_Week_Right,Paid_Left, Paid_Right,Paid from power.week_'+@tablename + '_table where M_Distributor_ID ='+@did exec sp_executesql @SQLString
set @i =@i + 1
end
select * from #salesdetail
end
exec salessample '332009','750123335547'
2. Join table without relationship between them..........
select a.This_Week_Left,a.This_Week_Right,a.Last_Week_Left,a.Last_Week_Right,a.Paid_Left,a.Paid_Right,a.Paid,b.orbitratefrom Power.Week_402010_table a, Power.Orbit_Rates b where a.m_distributor_id ='750123335547' and b.week_details ='402010'

No comments:

Post a Comment