Click here to Skip to main content
15,914,360 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to add some leves in my table ... but that table has got different company as well .. i want to add only once and that will be get added to all companies .. how can i do that in sql
Posted
Comments
Maciej Los 18-Jul-13 6:38am    
I don't get you... ;(
Please, be more specific and provride more details including example data and expected output.
Torakami 18-Jul-13 6:50am    
I have column companyId compnayNames Leaves
all has got some leavenames.. say Annual,study n all .. now what if I just want to add new leaves but that will be applicable for all companies .. that means all companies will have new leaves .
ArunRajendra 18-Jul-13 6:59am    
Is it all in a single table or two different tables?
Torakami 18-Jul-13 7:00am    
Its in single table.. I wanted to add new leaves and avalaible companies will also get updated with that new leave that means .. all comanies will have new leaves
Torakami 18-Jul-13 7:28am    
This is my Table details


CompanyId AbsenceTypeName AbsenceTypeId colorcode TotalLeaves DataForYear
41 Casual Leave 124 #800000 NULL NULL
41 Paid Leaves 125 #A52A2A NULL NULL
41 Annual Leave 126 #800080 200 2013

Try this solution. Replace @t with your table name and also inclue other fields which you need to add to the records.

SQL
insert into @t (CompanyId,AbsenceTypeName)
select distinct CompanyId,'New Leave' from @t
 
Share this answer
 
Have a look at example:
SQL
DECLARE @tmp TABLE (CompanyId INT, AbsenceTypeName VARCHAR(30), AbsenceTypeId INT, colorcode VARCHAR(30) NULL, TotalLeaves INT NULL, DataForYear INT NULL)

INSERT INTO @tmp (CompanyId, AbsenceTypeName, AbsenceTypeId, colorcode, TotalLeaves, DataForYear)
SELECT 41, 'Casual Leave', 124, '#800000', NULL, NULL
UNION ALL SELECT 41, 'Paid Leaves', 125, '#A52A2A', NULL, NULL
UNION ALL SELECT 41, 'Annual Leave', 126, '#800080', 200, 2013

SELECT *
FROM @tmp

INSERT INTO @tmp (CompanyId, AbsenceTypeName, AbsenceTypeId, colorcode, TotalLeaves, DataForYear)
SELECT CompanyID, 'New Leave', (SELECT MAX(AbsenceTypeID) +1 FROM @tmp), NULL, NULL, NULL
FROM @tmp

SELECT *
FROM @tmp
 
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