c# - "Must declare variable", but when I declare it, "variable already declared" -
this question has answer here:
- sql server output clause scalar variable 2 answers
i'm generating insert sql returns primary key caller. sql generated arbitrary table, can't use scope_identity() because not every table uses identity. when execute query, ms sql complains output var not declared, says it's declared when declare it. damned if do, damned if don't.
var parameters = new dynamicparameters(); parameters.add("d", direction:parameterdirection.output, size:8000); // (add input params a, b, c) remoteconnection.execute(sql, parameters);
sql:
-- error: must declare table variable "@d" insert blacklist (databaseconnectionid,tableschema,tablename) output inserted.id @d values (@a,@b,@c)
i declare variable:
declare @d int insert blacklist (databaseconnectionid,tableschema,tablename) output inserted.id @d values (@a,@b,@c) -- error: variable name '@d' has been declared. variable names must unique within query batch or stored procedure.
how do this?
you need declare @d
table
variable:
declare @d table ( id int ); insert blacklist (databaseconnectionid,tableschema,tablename) output inserted.id @d values (@a,@b,@c)
Comments
Post a Comment