Hello again,
please advice,
How to create a view in sql server 2005 express DB, using excel vba and then to use it in the next query?
like I do it with access
On Error Resume Next
dbs.QueryDefs.Delete "SumDmnd0"
On Error GoTo 0
Set tmp = dbs.CreateQueryDef("SumDmnd0", sql) ' sql = sql string for the view
if do you have sample, it will be nice.
Thank you,
Yalon
if you just want to create the view so you can use it in the query, then you are better of using CTE
CTE lets you define a view that only live for a single query, for example:
with my_cte (col1 , col2) as
(select col1, col2 from my_table where col1=1)
select * from my_cte
where col2 =2
Where this code is written?
under, VBA of excel ?
what references should be loaded to VBA ?
Do you have sample written in VBA?
please advice.
Thank you
Is this what you ask?
WITH SumDmnd0( MMItem , TransType, TransQty, DemandNxtlvl, ToDate) as (SELECT TDisplay.MMItem, TDisplay.TransType, TDisplay.TransQty, TDisplay.DemandNxtlvl, TDisplay.ToDate FROM TDisplay WHERE TDisplay.TransQty < 0 AND TDisplay.ItemBomLvl = 6 AND TDisplay.DemandNxtlvl > 0 ;)SELECT SumDmnd0.MMItem, IIf(Year([ToDate])*100+Month([ToDate])< Year(Date())*100+Month(Date()), Year(Date())*100+Month(Date()), Year([ToDate])*100+Month([ToDate])) AS MntDmnd, Sum(SumDmnd0.DemandNxtlvl) AS DmndNxtlvl, First(TItems.HanItem) AS HanItem, First(TItems.MrpCtrl) AS MrpCtrl, First(TPlanParam.ActiveForPO) AS ActiveForPO FROM (SumDmnd0 INNER JOIN TItems ON SumDmnd0.MMItem = TItems.MMItem) LEFT JOIN TPlanParam ON (TItems.MMItem = TPlanParam.MMitem AND TPlanParam.Loc = 'HN01') GROUP BY SumDmnd0.MMItem, IIf(Year([ToDate])*100 + Month([ToDate]) < Year(Date())*100+Month(Date()), Year(Date())*100+Month(Date()), Year([ToDate])*100+Month([ToDate]));
Microsoft Excel
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
CTE lets you define a view that only live for a single query, for example:
with my_cte (col1 , col2) as
(select col1, col2 from my_table where col1=1)
select * from my_cte
where col2 =2