dbTalk Databases Forums  

t-sql UDF syntax error please help!

comp.database.ms-access comp.database.ms-access


Discuss t-sql UDF syntax error please help! in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dave
 
Posts: n/a

Default t-sql UDF syntax error please help! - 08-10-2004 , 10:18 AM






Hi,

I'm running Access '03, SQL SERVER 2k on Windows XP SP1. I've not got
a ton of experience in writing UDF's for t-sql.

In SQL Query Analyzer, I'm trying to write a user defined scalar
function that returns a bit. I'm getting a vague error- so I'm not
quite sure what's wrong. I want the function to return true if the
parameter varchar matches one of three varchar's.

The error i'm getting is "[Microsoft][ODBC SQL Server Driver]Syntax
error or access violation". Other than that I'm

Code follows:

CREATE FUNCTION Kraut_Full.dbo.usefulgrouptest (@groupname AS
VARCHAR(255))
RETURNS BIT
AS
BEGIN
DECLARE @supheir varchar(20)
DECLARE @compheir varchar(20)
DECLARE @socheir varchar (20)
SET @supheir="alt.support"
SET @compheir="comp."
SET @socheir = "rec."
RETURN ((LEFT(@groupname, LEN(@supheir))=@supheir) OR (LEFT(@tmpstr,
LEN(@compheir))=@compheir) OR (Left(@tmpstr, LEN(@socheir))=@socheir))

--I've also tried this:

CREATE FUNCTION Kraut_Full.dbo.usefulgrouptest (@groupname AS
VARCHAR(255))
RETURNS BIT
AS
BEGIN
DECLARE @supheir varchar(20)
DECLARE @compheir varchar(20)
DECLARE @socheir varchar (20)
DECLARE @tmpstr varchar (255)
SET @supheir="alt.support"
SET @compheir="comp."
SET @socheir = "rec."

IF (LEFT(@tmpstr, LEN(@supheir))=@supheir){
return TRUE}
else if (LEFT(@tmpstr, LEN(@compheir))=@compheir){
return TRUE}
else if (Left(@tmpstr, LEN(@socheir))=@socheir){
return TRUE}
else return false
END

So, I'd appreciate any help someone can give on this. I'm aware that
multiple declarations/assignments can be done at once- but right now
I'm just trying to get it to work.

Thanks in advance,
Dave

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.