Viewing 15 posts - 31 through 45 (of 92 total)
the (@sqlStr) seems to have worked, thanks
December 6, 2013 at 7:30 am
ok here's the completed solution, thanks to all who helped....
-- destroy staging table if exists
IF OBJECT_ID('tbl_TestTable', 'U') IS NOT NULL
begin
DROP TABLE tbl_TestTable
end
-- create the temp table
create table tbl_TestTable(
AccountId varchar(6),
StockId varchar(7),
[Jan...
December 6, 2013 at 3:28 am
Thats just what I was after. I can create the dynamic column string from here. Thanks.
December 5, 2013 at 11:35 am
perfect thanks
November 25, 2013 at 11:23 am
got it....
just needed to add brackets to the @query variable when it's being executed to stop it being mistaken for a stored proc, so:
exec (@query)
November 13, 2013 at 1:42 pm
i've created my query string but am getting another issue.
when i use
-- create the dynamic pivot
set @query = N'SELECT AccountId, AccountName, StockGroup, StockGroupDescription, StockId, StockCode, StockDescription, ' +...
November 13, 2013 at 10:24 am
thanks both. really interesting stuff.
Dwain Camps, How to Design, Build and Test a Dynamic Search Stored Procedure was really useful.
November 13, 2013 at 3:12 am
thanks, i'll check that out.
believe me, our anal codes have been the humour in many a meeting. 🙂
November 7, 2013 at 9:13 am
well thats 2 new things i've learnt, correlated query and cross apply. both of which i can see myself using again.
thanks again 🙂
September 12, 2013 at 8:13 am
cracked it!!!
i never wanted to use the cost in the volume table. it should always come from the costing table.
so....
--the query
SELECT s.Year, s.Customer, s.StockCode, s.MonthNo, s.Volume,
CASE
WHEN Cost IS...
September 12, 2013 at 2:32 am
thanks again
the reason i need this is so that i can have a cost for a product now (say, Jan) which i know is going to have a cost change...
September 12, 2013 at 1:42 am
getting closer. sorry, if i add a 3rd costing i get the second cost carried forward. so...
Year.........MonthNo.....Volume.....Cost
2013........1................5000........1
2013........2................4000........1
2013........3................5000........1.5
2013........4................2000........1.5
2013........5................5000........1.5
2013........6................3000........1.5
2013........7................7000........1.5
2013........8................5000........1.5
2013........9................3000........1.5
2013........10................7000........1.62
2013........11................5000........1.5
2013........12................9000........1.5
--the query
SELECT s.Year, s.Customer, s.StockCode, s.MonthNo, s.Volume,
CASE
WHEN Cost IS NULL THEN (SELECT...
September 11, 2013 at 1:25 pm
Viewing 15 posts - 31 through 45 (of 92 total)