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