Author |
Topic |
ahmadjamalkhan
Starting Member
36 Posts |
Posted - 2009-01-09 : 06:12:24
|
HiFollowing SP takes two parameters , start and stop , for example start (23:10:19) and stop (23:14:19)CREATE PROCEDURE [dbo].[increment_minutes] @start datetime, @stop datetimeASSELECT DATEADD(second,60*number,@start)FROM master..spt_valuesWHERE type='p'AND DATEADD(second,60*number,@start)<=@stopGOI have table which has start and stop values , i want to pass thoses values one by one to this store procedureand insert the result into a table.Thanks for your help. |
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-09 : 06:45:10
|
alter PROCEDURE [dbo].[increment_minutes] @start datetime, @stop datetimeASset nocount on beginSELECT DATEADD(second,60*number,@start)as datevalue INTO urtableFROM master..spt_valuesWHERE type='p'AND DATEADD(second,60*number,@start)<=@stopset nocount offend |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-09 : 06:46:41
|
make it a functionCREATE PROCEDURE [dbo].[increment_minutes] (@start datetime, @stop datetime)RETURNS @RESULTS TABLEASRETURN(SELECT DATEADD(second,60*number,@start)FROM master..spt_valuesWHERE type='p'AND DATEADD(second,60*number,@start)<=@stop)GOthen use it as belowSELECT *FROM yourTable tCROSS APPLY dbo.[increment_minutes](t.field1,t.field2)f |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-09 : 06:47:15
|
quote: Originally posted by bklr alter PROCEDURE [dbo].[increment_minutes] @start datetime, @stop datetimeASset nocount on beginSELECT DATEADD(second,60*number,@start)as datevalue INTO urtableFROM master..spt_valuesWHERE type='p'AND DATEADD(second,60*number,@start)<=@stopset nocount offend
have you read question at all? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-09 : 06:49:20
|
just noticed this is 2000 forum. in that case ,cross apply wont work. you might need to use cursor or while loop and call function inside that |
|
|
ahmadjamalkhan
Starting Member
36 Posts |
Posted - 2009-01-09 : 07:33:40
|
Hi guysThanks for the help. however I am lost now. I am using sql server 2000. And have no idea about cursors. You help would be highly appreciated. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-09 : 08:39:24
|
quote: Originally posted by ahmadjamalkhan Hi guysThanks for the help. however I am lost now. I am using sql server 2000. And have no idea about cursors. You help would be highly appreciated.
just was thinking why cant you do this inline? wont below be enough?SELECT t.columns...,DATEADD(second,60*v.number,t.startdate)FROM YourTable tCROSS JOIN master..spt_values vWHERE v.type='p'AND DATEADD(second,60*v.number,t.startdate)<=t.enddate |
|
|
ahmadjamalkhan
Starting Member
36 Posts |
Posted - 2009-02-23 : 07:42:59
|
It works , Thanks for your helpCheers |
|
|
|