Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
Hi,
I'm using a direct query SQL in PBI. While using a DECLARE statement, it throws an error
Incorrect syntax near the keyqord 'DECLARE'. Incorrect syntax near ')'
My SQL statement is as follows:
DECLARE @effect_date as date;
Set @effect_date= (select distinct effective_date from in.input_table)
select * from abc
join ....
group by....
Any help is greatly appreciated.
Hey if anyone still looking for solution try to change your query , use cte instead of declare .
using declare :
DECLARE @effect_date as date;
Set @effect_date= (select distinct effective_date from in.input_table)
select * from abc
join ....
group by....
using cte:
WITH date AS (
SELECT
distinct effective_date from in.input_table AS effect_date)
SELECT * FROM date
hope it helps
Hi @Anonymous ,
Can this query return data correctly in SSMS?
Best Regards,
Jay
@Anonymous can you try this
DECLARE @effect_date date= (select distinct effective_date from in.input_table)
select * from abc
join ....
group by....
@Anonymous , This you can use as sub query, Try that way
select * from abc
join ....
where date in (select distinct effective_date from in.input_table)
group by....
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
80 | |
40 | |
31 | |
27 | |
27 |