Showing posts with label references. Show all posts
Showing posts with label references. Show all posts

Monday, March 19, 2012

Newbie needs help with User Defined Functions

Well I have never worked with SQL Server before and I am trying to figure things out on my own. I have references that I have been using to teach myself how to use SQL Server. I have run into a problem thou. I have to use an if statement in this User Defined Function. But I'm getting compiling errors on the IFs, ELSE IFs and the THENs. Can someone please tell me what is wrong with the syntax of my function. I have pasted it below. Any help given will be very much appreciated. Thanks in advance.

CREATE FUNCTION pbaweb.MonthTransForm
(
@.MonthNumber CHAR(2)
)
RETURNS CHAR

AS

BEGIN

IF(SELECT PayMonth from GroupActivity) = "1"

THEN

DECLARE @.MonthTitle VARChar(15)
Set @.MonthTitle = "January"
RETURN @.Monthtitle;

ELSE IF (SELECT PayMonth from GroupActivity) = "2" THEN
set @.MonthTitle = "Feburary"
RETURN @.Monthtitle;
ELSE IF (SELECT PayMonth from GroupActivity) = "3" THEN
set @.MonthTitle = "March"
RETURN @.Monthtitle;
ELSE IF (SELECT PayMonth from GroupActivity) = "4" THEN
set @.MonthTitle = "April"
RETURN @.Monthtitle;
ELSE IF (SELECT PayMonth from GroupActivity) = "5" THEN
set @.MonthTitle = "May"
RETURN @.Monthtitle;
END IF;
END;Hi,

Check BOL for IF ELSE syntax. THEN is not part of IF statement in SQL

IF Boolean_expression
{ sql_statement | statement_block }
[ ELSE
{ sql_statement | statement_block } ]

Best of luck|||DeepakKhattar is correct, there is no THEN, you would use BEGIN with END.

IF Boolean_expression BEGIN
{ sql_statement | statement_block }
END

However in your case you should look at the CASE statement
SELECT @.MonthTitle = CASE
WHEN PayMonth = "1" THEN "January"
WHEN PayMonth = "2" THEN "February"
WHEN PayMonth = "3" THEN "March"
.
.
.
ELSE "December"
END
FROM GroupActivity

Monday, February 20, 2012

newbee - Where can I find sqlxmlbulkload

I want to import large XML files into my SQL 200 server. Several articles I
read all refer to the XML Bulk Load tool with references to the
msdn.microsoft.com/xml site
Here I find more articles on how to use this tool, but not the download
itsselt.
Where can I find this?It's included in SQLXML - the latest version is at
http://www.microsoft.com/downloads/...DisplayLang=en.
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"Nils" <Nils@.discussions.microsoft.com> wrote in message
news:25D3844C-B7E7-47FE-8A4D-644073B6E9CB@.microsoft.com...
I want to import large XML files into my SQL 200 server. Several articles I
read all refer to the XML Bulk Load tool with references to the
msdn.microsoft.com/xml site
Here I find more articles on how to use this tool, but not the download
itsselt.
Where can I find this?

newbee - Where can I find sqlxmlbulkload

I want to import large XML files into my SQL 200 server. Several articles I
read all refer to the XML Bulk Load tool with references to the
msdn.microsoft.com/xml site
Here I find more articles on how to use this tool, but not the download
itsselt.
Where can I find this?
It's included in SQLXML - the latest version is at
http://www.microsoft.com/downloads/d...isplayLang=en.
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"Nils" <Nils@.discussions.microsoft.com> wrote in message
news:25D3844C-B7E7-47FE-8A4D-644073B6E9CB@.microsoft.com...
I want to import large XML files into my SQL 200 server. Several articles I
read all refer to the XML Bulk Load tool with references to the
msdn.microsoft.com/xml site
Here I find more articles on how to use this tool, but not the download
itsselt.
Where can I find this?