| Author |
Topic |
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-02-07 : 05:00:27
|
| Good morning everyone.I am trying to select a couple of UDF but to make up a date for egselect dbo.last_Day_Previous_Month () + '-' + dbo.First_Day_Previous_Month () + '-' + [dbo].[Present_year] ()could someone point me in the right direction pleaseKind RegardsRobMCTS / MCITP certified |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-02-07 : 05:12:00
|
| What should be the format of your output? Your requirements are not making sense...you say that you want to make up a date but "last_Day_Previous_Month" + "First_Day_Previous_Month" + year(getdate()) will for sure not be a date.- LumbagoMy blog-> www.thefirstsql.com |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-07 : 05:13:01
|
| What was the error you got?If the return type of the functions is Integer, you need to convert them to varchar during concatenationMadhivananFailing to plan is Planning to fail |
 |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-02-07 : 05:23:13
|
| i want it to readdd-mm-yyyyerror i receive is Conversion failed when converting the varchar value '_' to data type int. |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-07 : 05:32:04
|
| as madhi suggested, convert the returned values of functions to Varchar, it would be somehow like...convert(varchar(2),dbo.last_Day_Previous_Month ())orltrim(rtrim(str(dbo.last_Day_Previous_Month ()))) |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-07 : 05:32:54
|
quote: Originally posted by MIK_2008 as madhivanan suggested, convert the returned values of functions to Varchar, it would be somehow like...convert(varchar(2),dbo.last_Day_Previous_Month ())orltrim(rtrim(str(dbo.last_Day_Previous_Month ())))
|
 |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-02-07 : 05:37:01
|
| what about when i want to have '-' in between the variablesselect dbo.last_Day_Previous_Month () + '-' + dbo.First_Day_Previous_Month () + '-' + [dbo].[Present_year] () |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-07 : 05:40:25
|
let them as they are select convert(varchar(2),dbo.last_Day_Previous_Month ()) + '-' + convert(varchar(2),dbo.First_Day_Previous_Month ()) + '-' + convert(varchar(2),dbo.Present_year ()) |
 |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-02-07 : 05:53:22
|
| sorry about thiswhat about select '0' + day (dbo.first_Day_Previous_Month ()) + '-' + convert(varchar(3), DATENAME (m,DATEADD (m,-1,getdate()))) + '-' + convert(int,dbo.Present_year ())i receive Conversion failed when converting the varchar value 'Jan' to data type int. |
 |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-02-07 : 05:57:18
|
| so in the end i want it to readdd-jan-yyyy |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-07 : 07:57:43
|
| Why are you using function? Look at convert function in SQL Server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-02-07 : 09:04:01
|
| ok thank you very much for your help |
 |
|
|
|