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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 one date insert 3 times

Author  Topic 

hissam78
Starting Member

14 Posts

Posted - 2011-08-29 : 05:37:32
Following code will insert the date one by one i want to insert one date 3 times e.g. 01-jun-2011

declare
V_Counter DATE := '01-JUN-2011';
V_Counter1 DATE :='30-JUL-2011';
BEGIN
WHILE v_Counter <= v_Counter1 LOOP
INSERT INTO shift_schedule_final (date1) values (v_counter);
v_Counter := v_Counter + 1;
END LOOP;
END;

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-08-29 : 05:46:00
What is the business requirement? Why are you using cursor for this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-29 : 05:47:15
are you using Microsoft SQL Server ? ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hissam78
Starting Member

14 Posts

Posted - 2011-08-30 : 00:25:41
quote:
Originally posted by madhivanan

What is the business requirement? Why are you using cursor for this?

Madhivanan

Failing to plan is Planning to fail

basically i want to make a schedule for payroll. i need to insert the dates for three shifts one day three shifts it means three dates of same day i need to insert if any solution other than the above mentioned u have please tell me.

Go to Top of Page

hissam78
Starting Member

14 Posts

Posted - 2011-08-30 : 00:27:13
quote:
Originally posted by khtan

are you using Microsoft SQL Server ? ?


KH
[spoiler]Time is always against us[/spoiler]

yes my responsibility is to write the queries in sql for both the platforms sql server as well as oracle sql/plsql

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-30 : 00:38:08
I am not familiar with PS SQL syntax.

For SQL Server, this is how you do it

declare @dte date

select @dte = '2011-07-01'
insert into shift_schedule_final (date1)
values (@dte), (@dte), (@dte)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -