Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am a bit of a SQL hack and am try

Status
Not open for further replies.

KRobinson

Programmer
Dec 10, 2000
5
CA
I am a bit of a SQL hack and am trying to create a view for use in Crystal Reports. I have a table called preferences where a user sets his schedule start time and end time along with the intervals between appointments. I have some code that works to populate a table (see below) however I would like to use a view (w/o creating or populating a table). Is this possible. To expalin the code a bit the fields start_time, end_time and interval are varchar in the db so I convert them to integer. Also, the time is stored as 24 hr (string) ie. 5:15 pm is 1715 hence the modulos math. If a view is not possible should I just use temp table (create it, populate it and blow it away when I'm done?). Thanks for the help.


********************************
Declare @STime as Int
Declare @STimepc1 as Int
Declare @STimepc2 as Int
Declare @SFTime as NVarchar(20)
Declare @ETime as Int
Declare @ETimepc1 as Int
Declare @ETimepc2 as Int
Declare @EFTime as NVarchar(20)
Declare @Interval as Int

Select @STime = Cast(start_time as int), @ETime = Cast(end_time as int),
@Interval = Cast(time_interval as int) from preferences where [User_Id] = 1

If @STime < 100
Begin
Set @SFTime = '00'+':'+Cast(@STime as nvarchar(10))
End
Else
Begin
Set @STimepc1 = @STime/100
Set @STimepc2 = (@STime % 100)
Set @SFTime = Cast(@STimepc1 as nvarchar(10))+':'+Cast(@STimepc2 as nvarchar(10))
End

If @ETime < 100
Begin
Set @EFTime = '00'+':'+Cast(@ETime as nvarchar(10))
End
Else
Begin
Set @ETimepc1 = @ETime/100
Set @ETimepc2 = (@ETime % 100)
Set @EFTime = Cast(@ETimepc1 as nvarchar(10))+':'+Cast(@ETimepc2 as nvarchar(10))
End

WHILE Convert(smalldatetime,@SFTime) < Convert(smalldatetime,@EFTime)
BEGIN
Select @SFTime
Insert into TimeTable(Start_time)
Values(CONVERT ( smalldatetime, @SFTime, 14 ))
Set @SFTime = dateadd(minute, @Interval, @SFTime)
IF Convert(smalldatetime,@SFTime) = Convert(smalldatetime,@EFTime)
BREAK
ELSE
CONTINUE
END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top