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
 General SQL Server Forums
 New to SQL Server Programming
 SQL script error

Author  Topic 

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 11:56:13
>

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 12:01:12
It would be GREAT to post the error message!
But I think it is because you are using == instead of =

edit: typo

No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 12:02:55
And more than one statement in an IF needs begin and end
IF @vchEntity == 'NURSE'
BEGIN
SET @vchStringEntity ='-NCAT-NCLV-'
SET @vchTemp = 'nurse.xml'
END


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 12:03:46
And I dont know INTER JOIN


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 12:05:25
And CHAR() converts an INT to an ASCII character.

Do you use MS SQL Server?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 12:08:12
Hi Guys, Thanks for your help. This script is a homework excercise for my nephew, where the teacher have asked him to spot the mistakes. All your help is much appreciated.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 12:12:43
There are more errors but you can find them step by step.
It is not a good idea to complete the homework this way...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 12:26:23
I understand, but it will aid me next time to help him by understanding this excercise.
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 12:38:23
Can somebody please point me to the other errors in this script. Webfred, by you pointing out ASCII character is required, what do you mean by this?

Thanks
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 13:02:08
Anyones thoughts would me much appreciated.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 13:27:14
quote:
Originally posted by ksingh

Can somebody please point me to the other errors in this script. Webfred, by you pointing out ASCII character is required, what do you mean by this?

Thanks


I mean the function CHAR() in your source code above makes no sense.
Maybe CHARINDEX() is what the teacher wants to see...
See docu: http://msdn.microsoft.com/en-us/library/ms186323.aspx


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 13:31:48
And @bitReturn should be of data type BIT and not INT because the function says: "returns bit" what is 0 or 1.
Furthermore I can't see where @bitReturn is set to value and what condition...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 13:33:32
Thanks for that. Looking from the script the count SELECT @intAnswer = count(*) command looks wrong to me.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 13:40:38
Yes indeed because @intAnswer is declared as bit and it should be INT.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 13:44:30
Should RETURNS bit be RETURNS INT?
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 13:47:23
I have changed SELECT @intAnswer = count(*) to SELECT count(*)

Is this a better way if conducting a count? Thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 13:51:34
That depends on requirement of that function.
I unfortunately don't know the instructions for that function and how it should be called and used.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 13:57:49
Thank you. What is the script meant to return? What is the script intended to do?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 14:03:55
I think it is the teachers part to give that incorrect code AND ALSO he has to say what is the script intended to do.
He don't has to ask riddles.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-20 : 14:16:47
I assume the function should return the counted rows but I don't really know...

so I would change RETURNS BIT to RETURNS INT.
then:
Select @intAnswer = count(*) from ...
then:
RETURN @intAnswer

So the functions returns the number of rows for the given conditions in the where clause.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ksingh
Starting Member

13 Posts

Posted - 2009-09-20 : 16:04:05
Thank you for all your help. You have been a great guru. Much appreciated. Karan.
Go to Top of Page
    Next Page

- Advertisement -