Author |
Topic |
virkarchetan
Starting Member
2 Posts |
Posted - 2011-04-14 : 02:27:41
|
how to pass date as parameter to stored procedurecreate procedure new_proc ( @from_date datetime , @to_date datetime) as create table #temp( tdate datetime, count int default 0)i want to pass @from date and @to_date how sholud i pass it!!!!!@chetu |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-04-14 : 02:32:06
|
specify the date in YYYY-MM-DD formatexec new_proc @from_date = '2011-04-01', @to_date = '2011-04-30' KH[spoiler]Time is always against us[/spoiler] |
|
|
virkarchetan
Starting Member
2 Posts |
Posted - 2011-04-14 : 02:49:51
|
create procedure new_proc ( @from_date datetime , @to_date datetime) as create table #temp( date datetime, count int default 0) while(@from_date <= @to_date) begin insert into #temp values('date','(@from_date)') set @from_date = @from_date+1 end --select * from #temp update #temp set count=X.count from(select date , count(1)as count from trade_detail group by date)as X where (#temp.date = X.date) select date,count(1)as count from #temp group by date exec new_proc @from_date = '2011-11-01', @to_date = '2011-11-30'this is my code it giveing the eroor"Syntax error converting the varchar value '(@from_date)' to a column of data type int."@chetu |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-04-14 : 03:04:03
|
this the place where its throwing error'set @from_date = @from_date+1'you cant just add +1 to a datetime colum...you need to use dateadd function to add +1 to it.if you want to add 1 day to the date you must usse select dateadd(dd,1,@from_date)it add +1 day to you date |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-04-14 : 03:05:50
|
Your problem with thisinsert into #temp values(@from_date,'(@from_date)') How can you store 'Date' and in count '(@from_date)'what output you needand even you cant run like this declare @from_date datetimeset @from_date='2011-11-01'+1select @from_dateset @from_date=@from_date+1select @from_DateRaghu' S |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-04-14 : 03:08:32
|
quote: Originally posted by raghuveer125 Your problem with thisinsert into #temp values(@from_date,'(@from_date)') How can you store 'Date' and in count '(@from_date)'what output you needRaghu' S
yes,raghu your point is correct...but see mine once |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-04-14 : 03:21:17
|
Ok here you can replace set @from_date = @from_date+1to this set @from_date=convert(datetime,@from_date+1)and more what you need output?declare @from_date datetimeset @from_date='2011-11-01'select @from_dateset @from_date=convert(datetime,@from_date+1)select @from_DateRaghu' S |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-04-14 : 03:34:12
|
See I don't know what are you looking for butIs that you are looking foralter procedure new_proc (@from_date datetime ,@to_date datetime)ascreate table #temp(date datetime,count int default 0)Declare @i intset @i=count(@from_Date)while(@from_date <= @to_date)begininsert into #temp values(@from_date,@i)--select * from #tempset @from_date=convert(datetime,@from_date+1)set @i=count(@from_Date)end--select * from #tempupdate #temp set count=X.countfrom(select date , count(1)as count from #tempgroup by date)as Xwhere (#temp.date = X.date)select date,count(1)as count from #tempgroup by dateexec new_proc @from_date = '2011-11-01', @to_date = '2011-11-30'Raghu' S |
|
|
|