Friday, August 2, 2013

How to pass mulltiple values to a single variable in SQL

instead of creating it as a variable, create a variable table as below which will help you..



Declare @Location TABLE
(
Loc VARCHAR(10)
)
insert into @Location
select '3021' as loc
union all
select '3022' as loc --- added this to show you how you can add more values to this...


SELECT
SUM(VEDW_F_UNAUDITED_POS_TRANSACTION.SALES_UNITS) AS SoldSalesUnits
FROM
EDW.Logical.VEDW_F_UNAUDITED_POS_TRANSACTION
INNER JOIN EDW.Calendar.TEDW_D_DATE_TYPE_1
ON VEDW_F_UNAUDITED_POS_TRANSACTION.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
AND TEDW_D_DATE_TYPE_1.DATE_SHORT = CONVERT (date, SYSDATETIME())
WHERE VEDW_F_UNAUDITED_POS_TRANSACTION.LOCATION_NUM in ( select loc from @Location)





Nothing is Permanent... even Knowledge.... <a href="http://everysolution.wordpress.com/"> </a>


No comments:

Post a Comment