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.
Author |
Topic |
rtr1900
Starting Member
48 Posts |
Posted - 2008-05-08 : 07:52:38
|
Hi,i haveSELECT COD_ART, DESCRIP, U1FROM MAE_ARTWHERE (COD_ART = 2500)ORDER BY COD_ARTThere is U1,U2,....U12I need to know if I can add a kind of way so that U1 changes in U2 in the month of february.I thought something likeSELECT COD_ART, DESCRIP, U&month(getdate()) AS Expr1FROM MAE_ARTWHERE (COD_ART = 2500)ORDER BY COD_ARTBut it tells me that the column U doesn´t exists (which is correct). How can I do that?Thx in advance |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-08 : 08:47:47
|
declare @sql varchar(8000)set @sql='SELECT COD_ART, DESCRIP, U'+cast(month(getdate()) as varchar(2))+' AS Expr1FROM MAE_ARTWHERE (COD_ART = 2500)ORDER BY COD_ART'EXEC(@sql)Also read about NormalisationMadhivananFailing to plan is Planning to fail |
 |
|
rtr1900
Starting Member
48 Posts |
Posted - 2008-05-08 : 09:15:12
|
Hi madhivanan,After executing the code, it tells me that the syntax is incorrect near the keyword 'AS'But checking the sql code it tells me it is ok.What could it be? The column name is correct an thtype is "Float 8". Should be alright, no? |
 |
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2008-05-08 : 09:51:20
|
Here's an alternative...SELECT COD_ART, DESCRIP, CASE MONTH(GETDATE()) WHEN 1 THEN U1 WHEN 2 THEN U2 WHEN 3 THEN U3 WHEN 4 THEN U4 WHEN 5 THEN U5 WHEN 6 THEN U6 WHEN 7 THEN U7 WHEN 8 THEN U8 WHEN 9 THEN U9 WHEN 10 THEN U10 WHEN 11 THEN U11 WHEN 12 THEN U12 END AS Expr1FROM MAE_ARTWHERE (COD_ART = 2500)ORDER BY COD_ART But definitely read about normalisation.Ryan Randall Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|
|