Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii ,

SQL
Insert into Holidays
Select @CompanyId,'New Year''s Day','',Convert(datetime, '01 January 2015', 103),
datename(dw,(Convert(datetime, '01 January 2015', 103))),
Year(Convert(datetime, '01 January 2015', 103)),0,1

,

I have written a cursor so all my holidays will gets added to all companies .. but i have only 5 type of holidays .. which will also gets repeated in all years till 2022

how can i manage my date column .. so i dont want to insert columns which requires date as well .. i have given my one column name which i am inserting ..
Posted

1 solution

If i understand you well...

If you would like to add holidays for each companies, you don't need cursor. All what you need is to use simple INSERT INTO with SELECT statement.

SQL
INSERT INTO Holidays (CompanyID, SomeField, OtherField, AnotherField, OneMoreField, SomeID1, SomeID2)
SELECT CompanyID, 'Day Description' AS SomeField, '' AS OtherField, datename(dw,(Convert(datetime, '01 January 2015', 103))) AS AnotherField,
Year(Convert(datetime, '01 January 2015', 103)) AS OneMoreField, 0 AS SomeID1, 1 AS SomeID2
FROM Companies


For further information, see here:
INSERT (T-SQL)[^]
INSERT Examples (T-SQL)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900