home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,827 of 19,505   
   Erland Sommarskog to NZDeveloper   
   Re: DateAdd - passing interval fom anoth   
   01 Jul 10 07:01:08   
   
   f35abd3e   
   From: esquel@sommarskog.se   
      
   NZDeveloper (grant@technologyworks.co.nz) writes:   
   > I have an expression in a view that calculates a date by adding a   
   > number of months using the dateadd function.   
   >   
   > I want to get both the datepart (m for month in my caase) and hte   
   > number (1-3 months) from other fields in my view.   
   >   
   > I've tried this   
   > DATEADD(dbo.tbl_PTDF_PreTreatDevFrequency.PTDF_DateAddInterval, -   
   > dbo.tbl_PTDF_PreTreatDevFrequency.PTDF_BaseUnit,   
   > dbo.VW_110_01_ChargePeriod.EWC_PeriodEndDate)   
   >   
   > but it bomb out with I try and run it with the following error:   
   >   
   > "dbo.tbl_PTDF_PreTreatDevFrequency.PTDF_DateAddInterval is not a valid   
   > dateadd option"   
   >   
   > The field dbo.tbl_PTDF_PreTreatDevFrequency.PTDF_DateAddInterval holds   
   > a text value of 'm'   
   >   
   > If I replace the datepart with m, it works, why cant I pass my value   
   > from dbo.tbl_PTDF_PreTreatDevFrequency.PTDF_DateAddInterval ?   
      
   Because you can't. And if you think of it's logical. Say that you have:   
      
      CREATE TABLE crap (m varchar(23) NOT NULL)   
      go   
      INSERT crap (m) VALUES('DAY')   
      
   SELECT dateadd(m, 1, getdate())   
   FROM   crap   
      
   If it would be possible to pass a column here, how would SQL Server   
   disambguiate between the column and the possible constant?   
      
      
      
   --   
   Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se   
      
   Books Online for SQL Server 2005 at   
   http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx   
   Books Online for SQL Server 2000 at   
   http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca