Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to handle Date

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-20 : 07:17:20
Abe writes "how can I use the date in sql? See the fifth line below after select' ,
when I excute this "sql @thisSQL" it does not take it as date, but it use it as numeric expression.
so how we can solve this case :
SET @thisSQL = '
SELECT ' + here I need to put the date variable (My Question) + ' as todate ,
fx_MenuSalesPeriod.STR_NBR as store,
fx_MenuSalesPeriod.ACCT_NBR as item ,
fx_MenuSalesPeriod.DESCRIPTION as Description,
fx_MenuSalesPeriod.SalesAmt as amt,
fx_MenuSalesPeriod.Qty as sold,
fx_MenuItemCost.TotalCost as foodPerfect,
fx_MenuItemCost.TotalCost * fx_MenuSalesPeriod.Qty AS TotalFoodPerfect ,
case when salesamt > 0 then cast(COALESCE(( fx_MenuItemCost.TotalCost * fx_MenuSalesPeriod.Qty /fx_MenuSalesPeriod.SalesAmt ) * 100,0) as decimal(12,2) ) else 0 end as Costper ,
cast( COALESCE((fx_MenuSalesPeriod.SalesAmt / ' + convert(varchar(12),@StoreSales) + ' ) * 100 ,0) as decimal(12,2)) as totalper
FROM dbo.fx_MenuItemCost(' + @Store + ') fx_MenuItemCost INNER JOIN
dbo.fx_MenuSalesPeriod(' + @FromDate + ',' + @ToDate + ',' + @Store + ') fx_MenuSalesPeriod ON fx_MenuItemCost.ACCT_NBR = fx_MenuSalesPeriod.ACCT_NBR
order by totalper desc '"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-20 : 08:06:50
Something like this:

SET @thisSQL = '
SELECT ''' + convert(varchar(20, @dtvar) + ''' as todate ,
fx_MenuSalesPeriod.STR_NBR as store,
fx_MenuSalesPeriod.ACCT_NBR as item ,
fx_MenuSalesPeriod.DESCRIPTION as Description,
fx_MenuSalesPeriod.SalesAmt as amt,
fx_MenuSalesPeriod.Qty as sold,
fx_MenuItemCost.TotalCost as foodPerfect,
fx_MenuItemCost.TotalCost * fx_MenuSalesPeriod.Qty AS TotalFoodPerfect ,
case when salesamt > 0 then cast(COALESCE(( fx_MenuItemCost.TotalCost * fx_MenuSalesPeriod.Qty /fx_MenuSalesPeriod.SalesAmt ) * 100,0) as decimal(12,2) ) else 0 end as Costper ,
cast( COALESCE((fx_MenuSalesPeriod.SalesAmt / ' + convert(varchar(12),@StoreSales) + ' ) * 100 ,0) as decimal(12,2)) as totalper
FROM dbo.fx_MenuItemCost(' + @Store + ') fx_MenuItemCost INNER JOIN
dbo.fx_MenuSalesPeriod(' + @FromDate + ',' + @ToDate + ',' + @Store + ') fx_MenuSalesPeriod ON fx_MenuItemCost.ACCT_NBR = fx_MenuSalesPeriod.ACCT_NBR
order by totalper desc'


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -