Create Procedure ssp_InsertClientDefaults(
@cid int
)
AS
BEGIN
INSERT INTO ClientTermData
(ClientID, TermID, NormCount, NormProb, DiscCount, DiscProb, Weight)
WHERE NOT EXISTS
(SELECT
@cid, GlobalTermData.TermID, GlobalTermData.NormCount, GlobalTermData.NormProb,
GlobalTermData.DiscCount, GlobalTermData.DiscProb, GlobalTermData.Weight
FROM GlobalTermData, DefaultTerms
WHERE DefaultTerms.TermID = GlobalTermData.TermID);
END
GO
I’m getting an error by ‘Where’. I can’t figure out whats wrong.
What you might have meant was this:
Edit
Explanation – as others have pointed out, you can’t return ‘select’ columns from a where clause back to the insert this way. Also, the exists function can check for just about anything at all – no need to put all the columns in the exists. And lastly, more of a style issue, but it is preferable to do an inner join rather than a cross join with a where join condition.