SQL query: incorrect syntax error

I get an error

incorrect syntax next to the WHERE keyword

with the following SQL statement:

SqlCommand scInsertCostSpilt = new SqlCommand("INSERT INTO [ASSETS_CC] ([DEPT], [CC], [PER_CENT]) WHERE [ASSET_NO] = @AssetNumber)" +
"Values (@AssetNumber, @Dept, @CC, @PerCent)" , DataAccess.AssetConnection);

What's wrong?

+5
source share
4 answers

I think you wrote the wrong request. Update as below given request:

INSERT INTO [ASSETS_CC] ([DEPT], [CC], [PER_CENT]) Values ( @Dept, @CC, @PerCent) 
+3
source

There is no statement in SQL insert statements WHERE(which makes sense because there is no record yet). You put identifiers along with all other values ​​if you want to insert a new record or use an operator UPDATEif you want to modify an existing record.

INSERT INTO [ASSETS_CC] ([ASSET_NO], [DEPT], [CC], [PER_CENT]) 
VALUES (@AssetNumber, @Dept, @CC, @PerCent)

or

UPDATE [ASSETS_CC]
SET [DEPT] =  @Dept, [CC] = @CC, [PER_CENT] = @PerCent
WHERE [ASSET_NO] = @AssetNumber
+7
source

ya go.

SqlCommand scInsertCostSpilt = new SqlCommand("INSERT ASSETS_CC (DEPT, CC, PER_CENT) Values (@AssetNumber, @Dept, @CC, @PerCent)" , DataAccess.AssetConnection);
+2

where, Insert.

SqlCommand scInsertCostSpilt = new SqlCommand("INSERT INTO ASSETS_CC (DEPT, CC, PER_CENT) Values (@AssetNumber, @Dept, @CC, @PerCent)" , DataAccess.AssetConnection);
0

All Articles