Domanda

I have a string that looks like this:

set @sqlstring = N'select @mindate = min(time), @maxdate = max(time) from ' + @st_churn_active_table;

I print it and it looks like this:

select @mindate = min(time), @maxdate = max(time) from derp.derp_table

I run sp_executesql with parameter definitions like this:

execute sp_executesql @sqlstring, N'@maxdate date,@mindate date'

It errors like this:

The parameterized query '(@maxdate date,@mindate date)select @mindate = min(time), @maxda' expects the parameter '@maxdate', which was not supplied.

String becomes
'(@maxdate date,@mindate date)select @mindate = min(time), @maxda'
The sql string is cut off, does anyone know why and how to fix this?

Thanks!

È stato utile?

Soluzione

First of all, sql server saw the whole string. It's only the error message that truncates it. Notice the error got the name of the missing parameter right, even though the truncated sql string only had part of the name.

Second, this isn't going to work how you want it to. You can't use output parameters that way with sp_executesql.

But finally to the problem of why it's throwing an error. I can't be sure, but I suspect the problem here is that there is a type mismatch, and so it can't use the parameter you gave it. I would hope that sql server would throw a better error message (complain about a type mismatch) in that situation, but I don't have sql server handy to test with and I can't think of any other reason for this to cause a problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top