I ran into a new problem yesterday with a WebI free-hand SQL query. We are on 4.2 SP09 Patch 4. For this query I am using a SQL Server 2014 server. Here is simplified version of my query…
DECLARE @SelectedValue VARCHAR(25)
SET @SelectedValue = ‘Whatever’
SELECT @SelectedValue AS [Selected Value]
That yields this error…
Any guesses as to why? I did finally figure it out. I just wanted to throw this out here as a fun challenge.
The issue is the use of “Select” in my variable name. I suppose it is looking for SELECT to signify the beginning of a statement that will return data.
So this works…
DECLARE @Value VARCHAR(25)
SET @Value = ‘Whatever’
SELECT @Value AS [Selected Value]
Note that I still have “Select” in my column name. So the problem is not just its presence in the code, but more specifically where it occurs in the code.
Amazing. I must admit, it’s that long since I’ve used freehand SQL as a data provider that I’d never think of or encounter the edge cases like this. Another reason to restrict use of it!