I have a query to insert some records using multiple Select statements My query is as follows
INSERT INTO tbl_StreetMaster
(
StreetName,
CityID,
StartPoint,
EndPoint,
StoreID,
IsActive,
CreationDate,
CreatedBy
)
SELECT
(SELECT a.StreetName,CAST(a.CityName AS INT),a.EndPointFrom,a.EndPointTo
FROM #TempRecords a
WHERE NOT EXISTS
(SELECT b.StreetID,b.StreetName FROM tbl_StreetMaster b
WHERE a.StreetName=b.StreetName and a.EndPointFrom=b.StartPoint and
a.EndPointTo=b.EndPoint and CAST(a.CityName AS INT)=b.CityID and b.IsActive=1
))
,
(SELECT a.StoreID FROM tbl_StoreGridMapping a
inner join tbl_GridMaster b on a.GridID=b.GridID
inner join #TempRecords c on b.GridCode=c.GridCode1
WHERE NOT EXISTS
(SELECT b.StreetID,b.StreetName FROM tbl_StreetMaster b
WHERE c.StreetName=b.StreetName and c.EndPointFrom=b.StartPoint and
c.EndPointTo=b.EndPoint and CAST(c.CityName AS INT)=b.CityID and b.IsActive=1))
,
1,GETDATE(),100
Even though I have right number of columns in my Select it gives me error all the time
The select list for the INSERT statement contains fewer items
than the insert list. The number of SELECT values must match the number of INSERT
columns.
Can any one help out with this.
8in theinsertand5in theselect1,GETDATE(),100from the last line