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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Incorrect syntax near ' '.

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 datetime
AS
BEGIN
   DECLARE @date_out datetime
   SET @date_out = CONVERT(datetime, CAST(@date_in AS CHAR(8)), 101)
   

RETURN @date_out
END

I 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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 this

11/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 date

I want to do a UDF so that we dont have to keep writing codes whenever we need to know age etc

I hope it explains
Go to Top of Page

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 Shaw
SQL Server MVP
Go to Top of Page

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 2005

Wrote 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.

Kr

Sarika
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -