Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorrect syntax for INSERT using INNER JOIN

Status
Not open for further replies.

WayneGretzky

Programmer
Jan 12, 2004
28
US
Insert into dbo.E_FINAL (TDate, TTime, ANumber, TCode, FieldCode, NewValue, IFlag, RCode, AS_400_UserID, ProductLoanTypeCode, NotUsed)
Select GetDate(), GetDate(), @AcctNumber, fc.FieldCode, @CaseNumber, 'I', ' ', ' ', ' ', ' '
INNER JOIN dbo.E_Field_FieldCode fc ON fc.FieldName = 'CaseNumber'

I get the error: Incorrect syntax near the keyword 'INNER'.
 

Missing "FROM sometable" between "Select" and "INNER JOIN"

 
yea, I see. But I'm not really selecting anything from a table, the values I'm selecting are hard coded values and also parameters....but I guess I'll just put FROM dbo.E_FINAL at the end anyway....is this the right thing to do? seems weird.
 
Well, I don't see how you can JOIN a second table without having a first. (Sort of like "What is the sound of one hand clapping?")

Why not just do this?
[tt]
INSERT INTO dbo.E_FINAL (TDate, TTime, ANumber, TCode,
FieldCode, NewValue,IFlag, RCode,
AS_400_UserID,
ProductLoanTypeCode, NotUsed)
SELECT GetDate(), GetDate(), @AcctNumber,
fc.FieldCode, @CaseNumber, 'I', ' ',
' ', ' ', ' '
FROM dbo.E_Field_FieldCode fc
WHERE fc.FieldName = 'CaseNumber'
[/tt]

One other observation. It would be better to provide the explicit column list for the INSERT INTO statement. If (and when) you add another column to the E_FINAL table, this code will break. But, if you listed the 11 columns you are using, having additional columns in the table won't matter. Unless of course you add the column by rebuilding the table and making it NOT NULL instead of simply altering the table by adding the column(s).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top