I have a list of values that, i.e.
in ('1xxx','12xx','21xx','98xx','00xx')
I want to use for an insert script. How can a write a for loop in SQL Server using each value within the loop? I'm think something like.
For value in ('1xxx','12xx','21xx','98xx','00xx')
select value
endloop;
Im trying to simply this
INSERT INTO [dbo].[TimeCard]
VALUES
('test'+Right(NewId(),12),'6121126800','5102289289',CONVERT(DATE,'01-01-2013'),CONVERT(DATE,'01-01-2013'),20,CURRENT_TIMESTAMP,NULL )
GO
INSERT INTO [dbo].[TimeCard]
VALUES
('test'+Right(NewId(),12),'6121126800','5102289289',CONVERT(DATE,'01-08-2013'),CONVERT(DATE,'01-08-2013'),20,CURRENT_TIMESTAMP,NULL)
GO
INSERT INTO [dbo].[TimeCard]
VALUES
('test'+Right(NewId(),12),'6121126800','5102289289',CONVERT(DATE,'01-15-2013'),CONVERT(DATE,'01-15-2013'),20,CURRENT_TIMESTAMP,NULL )
GO
....
I have to insert these records for several testing scenarios.
FOR EACH, it hasDO WHILE:Clicky But there are probably better ways to handle this than a loop, or cursors.