How to use variables inside a select (SQL Server)?
Is it possibile to use variables inside a select?
For example I've tried this manual query in a datareader
DECLARE @anno as int
set @anno = 2018
select * from table where myyear=@anno
When I've tried to show the result, I received the error from the Boardserver:
Must declare the scalar variable "@anno".
It would be very helpful if we could use also variables, especially in complex sql-statements.
Regards,
Egon.
Answers
-
Hi Egon Santoni,
if it is just for time, you could use standard sql-functions in your where statement like this:
In any other case, I'd propose to populate a rolap in your sql database with your variables and then use this ROLAP in a sub-select to populate a view. Then use the SQL DataReader to get the desired data from the view. This might even work in a direct join between the SQL table and the ROLAP (although I have not tried that yet).
Hope, this helps!
Kind Regards,
Helmut
4
Categories
- All Categories
- 1.8K Forums
- 1.7K Platform
- 109 Academy
- 283 Resources
- 3 Community Captains
- 1 About Community Captains
- 1 Meet the Community Captains
- 1 Topics & Thought Starters
- Board Manual
- 50 Best Practices
- 42 How-To Guides
- 25 Board Advocacy Program
- 159 Blog
- 4 Groups Hub
- 4 About Groups
- New Community Members
- DACH
- Japan
- Academy
- 2 Board Academy
- 7 ILT/VILT Course Catalogue
- 13 e-Learning Course Catalogue
- 4 Academy Forum
- 1.1K Idea Exchange
- 310 Partner Hub
- 2 Solution Sales Toolkits
- 92 Support
- 14 FAQ's
- Customer Support Portal
- 54 Support Articles
- BEAP