| Author |
Topic |
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-10-13 : 06:33:38
|
| Hello everyone.i have the below statement to select left and right of getdate()declare @TimeStamp varchar(10)select @TimeStamp = ( select right (getdate(), 7))select left (@TimeStamp, 5)but when i try and create a function with the above i get an error.function script i am using-------------------------------------------------------------------create function [dbo].[TimeStamp] ()returns varchar(10)as begindeclare @TimeStamp varchar(10)select @TimeStamp = ( select right (getdate(), 7))returnselect left (@TimeStamp, 5)end---------------------------------------------------------------------MCTS / MCITP certified |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-10-13 : 06:45:00
|
| You are not allowed to use non-deterministic functions inside other functions...i other words: you will have to pass getdate() as a parameter to the function to make it work.- LumbagoMy blog-> http://thefirstsql.com/2011/07/08/how-to-find-gaps-in-identity-columns-at-the-speed-of-light/ |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-13 : 06:48:19
|
You actually can use getdate() inside a function from SQL 2008 onwards.What version of SQL Server are you using ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-10-13 : 06:49:53
|
| what about a plan select statement.can you combine left and right in one statement like you would with datepart, datediff. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-13 : 06:50:56
|
i guess you must be not using SQL 2008 else you would have used the time data type KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-13 : 06:51:29
|
quote: Originally posted by masterdineen what about a plan select statement.can you combine left and right in one statement like you would with datepart, datediff.
Yes. you can KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-13 : 06:52:27
|
if you just want to get the current time in string HH:MM:SSselect convert(varchar(8), getdate(), 108) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-10-13 : 06:53:27
|
| o my god, of course. sorry to waste your time. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-13 : 08:30:46
|
no problem  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|