sql server programming:
Hi All, Once again, thanks for all the reply's on this one!!! As suggested here is the code that I am trying to run, this is taken from one of the web site's suggested. CREATE FUNCTION PROPERCASE ( @input varchar(8000) ) RETURNS varchar(8000) AS BEGIN IF @input IS NULL BEGIN RETURN NULL END DECLARE @output varchar(8000) DECLARE @ctr int, @len int, @found_at int DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int SET @ctr = 1 SET @len = LEN(@input) SET @output = '' SET @LOWER_CASE_a = 97 SET @LOWER_CASE_z = 122 SET @Delimiter = ' ,-' SET @UPPER_CASE_A = 65 SET @UPPER_CASE_Z = 90 WHILE @ctr <= @len BEGIN WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0 BEGIN SET @output = @output + SUBSTRING(@input,@ctr,1) SET @ctr = @ctr + 1 END IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a AND @LOWER_CASE_z BEGIN SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1)) END ELSE BEGIN SET @output = @output + SUBSTRING(@input,@ctr,1) END SET @ctr = @ctr + 1 WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 AND (@ctr <= @len) BEGIN IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A AND @UPPER_CASE_Z BEGIN SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1)) END ELSE BEGIN SET @output = @output + SUBSTRING(@input,@ctr,1) END SET @ctr = @ctr + 1 END END RETURN @output END ---------------------------------------------------------- And these are the error's that I am getting, it's probably something silly but between this and trying to get my spidering software to work, giving myself a headache!!! Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'FUNCTION'. Server: Msg 137, Level 15, State 1, Line 8 Must declare the variable '@input'. Server: Msg 178, Level 15, State 1, Line 10 A RETURN statement with a return status can only be used in a stored procedure. Server: Msg 137, Level 15, State 1, Line 18 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 28 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 30 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 34 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 36 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 40 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 45 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 47 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 49 Must declare the variable '@input'. Server: Msg 137, Level 15, State 1, Line 53 Must declare the variable '@input'. Server: Msg 178, Level 15, State 1, Line 59 A RETURN statement with a return status can only be used in a stored procedure. ---------------------------------------------------- Thanks Phil
Yes 100% sure, although I didn't set up the SQL here :-)), shall I take it you just cut and pasted it straight into a Query Ana. window and the executed it, with no changes? Thanks Phil [quoted text, click to view] >-----Original Message----- >Are you sure that you are using 2000 ;)? >Just curious. It worked fine here. > >-- >Roji. P. Thomas >SQL Server Programmer ;) >________________________ >"Phil" <harlequintp@blazemail.com> wrote in message >news:096b01c3b4b8$eabec9a0$a101280a@phx.gbl... >> Hi All, >> >> Once again, thanks for all the reply's on this one!!! >> As suggested here is the code that I am trying to run, this >> is taken from one of the web site's suggested. >> >> CREATE FUNCTION PROPERCASE >> ( >> @input varchar(8000) >> ) >> RETURNS varchar(8000) >> AS >> BEGIN >> IF @input IS NULL >> BEGIN >> RETURN NULL >> END >> >> DECLARE @output varchar(8000) >> DECLARE @ctr int, @len int, @found_at int >> DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter >> char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int >> >> SET @ctr = 1 >> SET @len = LEN(@input) >> SET @output = '' >> SET @LOWER_CASE_a = 97 >> SET @LOWER_CASE_z = 122 >> SET @Delimiter = ' ,-' >> SET @UPPER_CASE_A = 65 >> SET @UPPER_CASE_Z = 90 >> >> WHILE @ctr <= @len >> BEGIN >> WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0 >> BEGIN >> SET @output = @output + SUBSTRING(@input,@ctr,1) >> SET @ctr = @ctr + 1 >> END >> >> IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a >> AND @LOWER_CASE_z >> BEGIN >> SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1)) >> END >> ELSE >> BEGIN >> SET @output = @output + SUBSTRING(@input,@ctr,1) >> END >> >> SET @ctr = @ctr + 1 >> >> WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 >> AND (@ctr <= @len) >> BEGIN >> IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A >> AND @UPPER_CASE_Z >> BEGIN >> SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1)) >> END >> ELSE >> BEGIN >> SET @output = @output + SUBSTRING(@input,@ctr,1) >> END >> SET @ctr = @ctr + 1 >> END >> >> END >> RETURN @output >> END >> >> ---------------------------------------------------------- >> And these are the error's that I am getting, it's probably >> something silly but between this and trying to get my >> spidering software to work, giving myself a headache!!! >> >> Server: Msg 170, Level 15, State 1, Line 1 >> Line 1: Incorrect syntax near 'FUNCTION'. >> Server: Msg 137, Level 15, State 1, Line 8 >> Must declare the variable '@input'. >> Server: Msg 178, Level 15, State 1, Line 10 >> A RETURN statement with a return status can only be used in >> a stored procedure. >> Server: Msg 137, Level 15, State 1, Line 18 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 28 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 30 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 34 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 36 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 40 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 45 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 47 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 49 >> Must declare the variable '@input'. >> Server: Msg 137, Level 15, State 1, Line 53 >> Must declare the variable '@input'. >> Server: Msg 178, Level 15, State 1, Line 59 >> A RETURN statement with a return status can only be used in >> a stored procedure. >> >> ---------------------------------------------------- >> >> Thanks Phil >> > > >.
Perhaps the database is in 65 or 70 compatibility mode? -- Tibor Karaszi, SQL Server MVP Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver [quoted text, click to view] "Phil" <harlequintp@blazemail.com> wrote in message news:7ec301c3b4c0$7b185aa0$a601280a@phx.gbl... > Yes 100% sure, although I didn't set up the SQL here :-)), > shall I take it you just cut and pasted it straight into a > Query Ana. window and the executed it, with no changes? > > Thanks Phil > > >-----Original Message----- > >Are you sure that you are using 2000 ;)? > >Just curious. It worked fine here. > > > >-- > >Roji. P. Thomas > >SQL Server Programmer ;) > >________________________ > >"Phil" <harlequintp@blazemail.com> wrote in message > >news:096b01c3b4b8$eabec9a0$a101280a@phx.gbl... > >> Hi All, > >> > >> Once again, thanks for all the reply's on this one!!! > >> As suggested here is the code that I am trying to run, this > >> is taken from one of the web site's suggested. > >> > >> CREATE FUNCTION PROPERCASE > >> ( > >> @input varchar(8000) > >> ) > >> RETURNS varchar(8000) > >> AS > >> BEGIN > >> IF @input IS NULL > >> BEGIN > >> RETURN NULL > >> END > >> > >> DECLARE @output varchar(8000) > >> DECLARE @ctr int, @len int, @found_at int > >> DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter > >> char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int > >> > >> SET @ctr = 1 > >> SET @len = LEN(@input) > >> SET @output = '' > >> SET @LOWER_CASE_a = 97 > >> SET @LOWER_CASE_z = 122 > >> SET @Delimiter = ' ,-' > >> SET @UPPER_CASE_A = 65 > >> SET @UPPER_CASE_Z = 90 > >> > >> WHILE @ctr <= @len > >> BEGIN > >> WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0 > >> BEGIN > >> SET @output = @output + SUBSTRING(@input,@ctr,1) > >> SET @ctr = @ctr + 1 > >> END > >> > >> IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a > >> AND @LOWER_CASE_z > >> BEGIN > >> SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1)) > >> END > >> ELSE > >> BEGIN > >> SET @output = @output + SUBSTRING(@input,@ctr,1) > >> END > >> > >> SET @ctr = @ctr + 1 > >> > >> WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 > >> AND (@ctr <= @len) > >> BEGIN > >> IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A > >> AND @UPPER_CASE_Z > >> BEGIN > >> SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1)) > >> END > >> ELSE > >> BEGIN > >> SET @output = @output + SUBSTRING(@input,@ctr,1) > >> END > >> SET @ctr = @ctr + 1 > >> END > >> > >> END > >> RETURN @output > >> END > >> > >> ---------------------------------------------------------- > >> And these are the error's that I am getting, it's probably > >> something silly but between this and trying to get my > >> spidering software to work, giving myself a headache!!! > >> > >> Server: Msg 170, Level 15, State 1, Line 1 > >> Line 1: Incorrect syntax near 'FUNCTION'. > >> Server: Msg 137, Level 15, State 1, Line 8 > >> Must declare the variable '@input'. > >> Server: Msg 178, Level 15, State 1, Line 10 > >> A RETURN statement with a return status can only be used in > >> a stored procedure. > >> Server: Msg 137, Level 15, State 1, Line 18 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 28 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 30 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 34 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 36 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 40 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 45 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 47 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 49 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 53 > >> Must declare the variable '@input'. > >> Server: Msg 178, Level 15, State 1, Line 59 > >> A RETURN statement with a return status can only be used in > >> a stored procedure. > >> > >> ---------------------------------------------------- > >> > >> Thanks Phil > >> > > > > > >. > >
Are you sure that you are using 2000 ;)? Just curious. It worked fine here. -- Roji. P. Thomas SQL Server Programmer ;) ________________________ [quoted text, click to view] "Phil" <harlequintp@blazemail.com> wrote in message news:096b01c3b4b8$eabec9a0$a101280a@phx.gbl... > Hi All, > > Once again, thanks for all the reply's on this one!!! > As suggested here is the code that I am trying to run, this > is taken from one of the web site's suggested. > > CREATE FUNCTION PROPERCASE > ( > @input varchar(8000) > ) > RETURNS varchar(8000) > AS > BEGIN > IF @input IS NULL > BEGIN > RETURN NULL > END > > DECLARE @output varchar(8000) > DECLARE @ctr int, @len int, @found_at int > DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter > char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int > > SET @ctr = 1 > SET @len = LEN(@input) > SET @output = '' > SET @LOWER_CASE_a = 97 > SET @LOWER_CASE_z = 122 > SET @Delimiter = ' ,-' > SET @UPPER_CASE_A = 65 > SET @UPPER_CASE_Z = 90 > > WHILE @ctr <= @len > BEGIN > WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0 > BEGIN > SET @output = @output + SUBSTRING(@input,@ctr,1) > SET @ctr = @ctr + 1 > END > > IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a > AND @LOWER_CASE_z > BEGIN > SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1)) > END > ELSE > BEGIN > SET @output = @output + SUBSTRING(@input,@ctr,1) > END > > SET @ctr = @ctr + 1 > > WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 > AND (@ctr <= @len) > BEGIN > IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A > AND @UPPER_CASE_Z > BEGIN > SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1)) > END > ELSE > BEGIN > SET @output = @output + SUBSTRING(@input,@ctr,1) > END > SET @ctr = @ctr + 1 > END > > END > RETURN @output > END > > ---------------------------------------------------------- > And these are the error's that I am getting, it's probably > something silly but between this and trying to get my > spidering software to work, giving myself a headache!!! > > Server: Msg 170, Level 15, State 1, Line 1 > Line 1: Incorrect syntax near 'FUNCTION'. > Server: Msg 137, Level 15, State 1, Line 8 > Must declare the variable '@input'. > Server: Msg 178, Level 15, State 1, Line 10 > A RETURN statement with a return status can only be used in > a stored procedure. > Server: Msg 137, Level 15, State 1, Line 18 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 28 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 30 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 34 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 36 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 40 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 45 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 47 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 49 > Must declare the variable '@input'. > Server: Msg 137, Level 15, State 1, Line 53 > Must declare the variable '@input'. > Server: Msg 178, Level 15, State 1, Line 59 > A RETURN statement with a return status can only be used in > a stored procedure. > > ---------------------------------------------------- > > Thanks Phil >
Yes. Just copied the function from your post and executed it. And I can guarantee you that there is no Syntax error in the function. -- Roji. P. Thomas SQL Server Programmer ;) ________________________ [quoted text, click to view] "Phil" <harlequintp@blazemail.com> wrote in message news:7ec301c3b4c0$7b185aa0$a601280a@phx.gbl... > Yes 100% sure, although I didn't set up the SQL here :-)), > shall I take it you just cut and pasted it straight into a > Query Ana. window and the executed it, with no changes? > > Thanks Phil > > >-----Original Message----- > >Are you sure that you are using 2000 ;)? > >Just curious. It worked fine here. > > > >-- > >Roji. P. Thomas > >SQL Server Programmer ;) > >________________________ > >"Phil" <harlequintp@blazemail.com> wrote in message > >news:096b01c3b4b8$eabec9a0$a101280a@phx.gbl... > >> Hi All, > >> > >> Once again, thanks for all the reply's on this one!!! > >> As suggested here is the code that I am trying to run, this > >> is taken from one of the web site's suggested. > >> > >> CREATE FUNCTION PROPERCASE > >> ( > >> @input varchar(8000) > >> ) > >> RETURNS varchar(8000) > >> AS > >> BEGIN > >> IF @input IS NULL > >> BEGIN > >> RETURN NULL > >> END > >> > >> DECLARE @output varchar(8000) > >> DECLARE @ctr int, @len int, @found_at int > >> DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter > >> char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int > >> > >> SET @ctr = 1 > >> SET @len = LEN(@input) > >> SET @output = '' > >> SET @LOWER_CASE_a = 97 > >> SET @LOWER_CASE_z = 122 > >> SET @Delimiter = ' ,-' > >> SET @UPPER_CASE_A = 65 > >> SET @UPPER_CASE_Z = 90 > >> > >> WHILE @ctr <= @len > >> BEGIN > >> WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0 > >> BEGIN > >> SET @output = @output + SUBSTRING(@input,@ctr,1) > >> SET @ctr = @ctr + 1 > >> END > >> > >> IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a > >> AND @LOWER_CASE_z > >> BEGIN > >> SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1)) > >> END > >> ELSE > >> BEGIN > >> SET @output = @output + SUBSTRING(@input,@ctr,1) > >> END > >> > >> SET @ctr = @ctr + 1 > >> > >> WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 > >> AND (@ctr <= @len) > >> BEGIN > >> IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A > >> AND @UPPER_CASE_Z > >> BEGIN > >> SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1)) > >> END > >> ELSE > >> BEGIN > >> SET @output = @output + SUBSTRING(@input,@ctr,1) > >> END > >> SET @ctr = @ctr + 1 > >> END > >> > >> END > >> RETURN @output > >> END > >> > >> ---------------------------------------------------------- > >> And these are the error's that I am getting, it's probably > >> something silly but between this and trying to get my > >> spidering software to work, giving myself a headache!!! > >> > >> Server: Msg 170, Level 15, State 1, Line 1 > >> Line 1: Incorrect syntax near 'FUNCTION'. > >> Server: Msg 137, Level 15, State 1, Line 8 > >> Must declare the variable '@input'. > >> Server: Msg 178, Level 15, State 1, Line 10 > >> A RETURN statement with a return status can only be used in > >> a stored procedure. > >> Server: Msg 137, Level 15, State 1, Line 18 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 28 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 30 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 34 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 36 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 40 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 45 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 47 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 49 > >> Must declare the variable '@input'. > >> Server: Msg 137, Level 15, State 1, Line 53 > >> Must declare the variable '@input'. > >> Server: Msg 178, Level 15, State 1, Line 59 > >> A RETURN statement with a return status can only be used in > >> a stored procedure. > >> > >> ---------------------------------------------------- > >> > >> Thanks Phil > >> > > > > > >. > >
Don't see what you're looking for? Try a search.
|