I have a peculiar MSSQL DB which is used in accounting and each year is generating a new name based on the current year as 2008LH for 2008, 2009LH for 2009 and so on.
Obviously when the queries are designed within the same year, there is no problem but when we want to cross information is when the problems arise (sort of).
The following query lists the annual earnings and as you can see, it needs to be updated every year to add the latest DB.
I’m thinking to design a function which would automatically pick up all DBs regardless the year (20xxLH). Can someone pls give me some hints?
TIA
SELECT SUM(A) AS [2008], SUM(B)/> AS [2009], SUM(C) AS [2010] FROM (SELECT sum(amount) AS A, '0' AS B, '0' AS C FROM [2008LH]..d_albven UNION ALL SELECT '0' , sum(amount) , '0' FROM [2009LH]..d_albven UNION ALL SELECT '0' , '0' , sum(amount) FROM [2010LH]..d_albven) AS a

New Topic/Question
Reply



MultiQuote



|