c# - "Must declare variable", but when I declare it, "variable already declared" -


this question has answer here:

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -