1

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!

2 Answers 2

2

See: How to specify output parameters when you use the sp_executesql stored procedure in SQL Server

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.