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 |
skhurana
Starting Member
3 Posts |
Posted - 2011-09-22 : 04:31:16
|
Hi there,I am new to the forum and have only started exploring SQL server 2005. I am trying to write the following UDF in sql server 2005 and it is coming up with error. My code is as below:create FUNCTION dbo.udf_convert_int_date (@date_in int) RETURNS datetimeASBEGIN DECLARE @date_out datetime SET @date_out = CONVERT(datetime, CAST(@date_in AS CHAR(8)), 101) RETURN @date_outENDI am getting the error message : Incorrect syntax near ' '.Please can anybody help. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 05:06:00
|
how are you calling this udf? i dont think error is in code posted.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 05:07:05
|
and i dont understand reason why you're doing this in udf. Its quite simple and can be applied inline. I assume you're learning scalar udfs------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
skhurana
Starting Member
3 Posts |
Posted - 2011-09-22 : 05:11:23
|
Hi Vikas,Yes I am doing a Scaler UDF. When I try to execute the code..it gives me the error message. The way dates are stored in our internal systems is in a format like this11/12/2011 is stored like 2111211 so basically we add 1800 in the first 3 digits to get year and then the nest two are months and the last two are dateI want to do a UDF so that we dont have to keep writing codes whenever we need to know age etcI hope it explains |
 |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-09-22 : 06:49:01
|
There's no syntax error in what you've shown. If there's a syntax error it's in the way you're calling the udf. Post that.--Gail ShawSQL Server MVP |
 |
|
skhurana
Starting Member
3 Posts |
Posted - 2011-09-22 : 07:13:03
|
Hi I tried to google more and apparently it had something to do with the migration of Sql 2000 to 2005Wrote the code again and it worked.I am not sure what I was doing wrong but it is working now.Many thanks for your help.KrSarika |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 12:19:38
|
ok.glad that you sorted it out------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|