Monday, March 12, 2012

Nested IF statement and Declare problem

This is prolly more of a gut check, but needed to know if this looks right.
I am making another Scalar function..
CREATE FUNCTION [dbo].[EvalTradeCode]
(
@.tradeSymbol char(15)
)
RETURNS int(1)
AS
BEGIN
Declare @.intOffset int
If (left(tradesymbol, 1) = '@.')
If (isnumeric(left(right(tradesymbol, 6), 1))
@.intOffset = 1
If left(tradesymbol, 1) = '+'
If isnumeric(left(right(tradesymbol, 6), 1)
@.intOffset = 1
IF left(tradesymbol, 1) <>'@.' and left(tradesymbol, 1) <> '+'
If isnumeric(left(right(tradesymbol, 5), 1)
@.intOffset = 1
RETURN @.intOffset
END
I was getting an error because I was using the 'then' statement in there
(remember..i'm a VB programmer... and I did check out the bol site..lol)
I took the 'then' statements out. and now the only error that comes up is th
e:
'Oncorrect syntax near '@.intOffset' ' Error.
I'm not sure if this is because of the way that it's being used in the
function, or if i've got something bass ackwards.
Thanks for your input!
~Doc
www.krushradio.com - Internet Radio for the rest of usTry replacing
@.intOffset = 1
with
SET @.intOffset = 1
HTH
Vern
"Daniel Regalia" wrote:

> This is prolly more of a gut check, but needed to know if this looks right
.
> I am making another Scalar function..
> CREATE FUNCTION [dbo].[EvalTradeCode]
> (
> @.tradeSymbol char(15)
> )
> RETURNS int(1)
> AS
> BEGIN
> Declare @.intOffset int
> If (left(tradesymbol, 1) = '@.')
> If (isnumeric(left(right(tradesymbol, 6), 1))
> @.intOffset = 1
> If left(tradesymbol, 1) = '+'
> If isnumeric(left(right(tradesymbol, 6), 1)
> @.intOffset = 1
> IF left(tradesymbol, 1) <>'@.' and left(tradesymbol, 1) <> '+'
> If isnumeric(left(right(tradesymbol, 5), 1)
> @.intOffset = 1
> RETURN @.intOffset
> END
> I was getting an error because I was using the 'then' statement in there
> (remember..i'm a VB programmer... and I did check out the bol site..lol)
> I took the 'then' statements out. and now the only error that comes up is
the:
> 'Oncorrect syntax near '@.intOffset' ' Error.
> I'm not sure if this is because of the way that it's being used in the
> function, or if i've got something bass ackwards.
> Thanks for your input!
> ~Doc
> --
> www.krushradio.com - Internet Radio for the rest of us|||Not one.. there are lots of changes :)
no offences.
Here is the function.. Hope this helps.
CREATE FUNCTION [dbo].[EvalTradeCode]
(
@.tradeSymbol char(15)
)
RETURNS int
AS
BEGIN
Declare @.intOffset int
If (left(@.tradeSymbol, 1) = '@.')
If isnumeric(left(right(@.tradeSymbol, 6), 1)) = 1
set @.intOffset = 1
If left(@.tradeSymbol, 1) = '+'
If isnumeric(left(right(@.tradeSymbol, 6), 1)) = 1
set @.intOffset = 1
IF left(@.tradeSymbol, 1) <>'@.' and left(@.tradeSymbol, 1) <> '+'
If isnumeric(left(right(@.tradeSymbol, 5), 1)) = 1
set @.intOffset = 1
RETURN @.intOffset
END|||Gave it a shot....it didn't like it
Incorrect syntax near the keyword 'Set'
If (left(tradesymbol, 1) = '@.')
If (isnumeric(left(right(tradesymbol, 6), 1))
Set @.intOffset = 1
If left(tradesymbol, 1) = '+'
If isnumeric(left(right(tradesymbol, 6), 1)
Set @.intOffset = 1
IF left(tradesymbol, 1) <>'@.' and left(tradesymbol, 1) <> '+'
If isnumeric(left(right(tradesymbol, 5), 1)
Set @.intOffset = 1
--
www.krushradio.com - Internet Radio for the rest of us
"Vern Rabe" wrote:
> Try replacing
> @.intOffset = 1
> with
> SET @.intOffset = 1
> HTH
> Vern
> "Daniel Regalia" wrote:
>|||I feel it can better be written this way. You can validate better than me.
You should be a procedural logic expert :) Let me know.
CREATE FUNCTION [dbo].[EvalTradeCode]
(
@.tradeSymbol char(15)
)
RETURNS int
AS
BEGIN
Declare @.intOffset int
Set @.intOffset = 0
If (left(@.tradeSymbol, 1) = '@.') or (left(@.tradeSymbol, 1) = '+')
begin
If isnumeric(left(right(@.tradeSymbol, 6), 1)) = 1
set @.intOffset = 1
end
else
begin
If isnumeric(left(right(@.tradeSymbol, 5), 1)) = 1
set @.intOffset = 1
end
RETURN @.intOffset
END|||None Taken...
It's a learning experience for me :D. Just add this question to my beer
tab. Thanks OmniBuzz
~Doc
www.krushradio.com - Internet Radio for the rest of us
"Omnibuzz" wrote:

> Not one.. there are lots of changes :)
> no offences.
> Here is the function.. Hope this helps.
> CREATE FUNCTION [dbo].[EvalTradeCode]
> (
> @.tradeSymbol char(15)
> )
> RETURNS int
> AS
> BEGIN
> Declare @.intOffset int
> If (left(@.tradeSymbol, 1) = '@.')
> If isnumeric(left(right(@.tradeSymbol, 6), 1)) = 1
> set @.intOffset = 1
> If left(@.tradeSymbol, 1) = '+'
> If isnumeric(left(right(@.tradeSymbol, 6), 1)) = 1
> set @.intOffset = 1
> IF left(@.tradeSymbol, 1) <>'@.' and left(@.tradeSymbol, 1) <> '+'
> If isnumeric(left(right(@.tradeSymbol, 5), 1)) = 1
> set @.intOffset = 1
> RETURN @.intOffset
> END
>|||Sure Sir. I remember the first one you promised too..
Anything for a beer :)
"Daniel Regalia" wrote:
> None Taken...
> It's a learning experience for me :D. Just add this question to my beer
> tab. Thanks OmniBuzz
> ~Doc
>
> --
> www.krushradio.com - Internet Radio for the rest of us
>
> "Omnibuzz" wrote:
>|||One problem is that your parenthesis are not properly matching up. Another,
and this is just personal preference, is you are not using begin and end to
group your if else logic. I prefer to have a begin and end for every if
statement, and indent accordingly. It makes the code easier to follow, and
leaves no confusion as to the order of nested ifs.
"Daniel Regalia" <DanielRegalia@.discussions.microsoft.com> wrote in message
news:4618C615-2579-4999-B0BC-3DB935F7527F@.microsoft.com...
> This is prolly more of a gut check, but needed to know if this looks
right.
> I am making another Scalar function..
> CREATE FUNCTION [dbo].[EvalTradeCode]
> (
> @.tradeSymbol char(15)
> )
> RETURNS int(1)
> AS
> BEGIN
> Declare @.intOffset int
> If (left(tradesymbol, 1) = '@.')
> If (isnumeric(left(right(tradesymbol, 6), 1))
> @.intOffset = 1
> If left(tradesymbol, 1) = '+'
> If isnumeric(left(right(tradesymbol, 6), 1)
> @.intOffset = 1
> IF left(tradesymbol, 1) <>'@.' and left(tradesymbol, 1) <> '+'
> If isnumeric(left(right(tradesymbol, 5), 1)
> @.intOffset = 1
> RETURN @.intOffset
> END
> I was getting an error because I was using the 'then' statement in there
> (remember..i'm a VB programmer... and I did check out the bol site..lol)
> I took the 'then' statements out. and now the only error that comes up is
the:
> 'Oncorrect syntax near '@.intOffset' ' Error.
> I'm not sure if this is because of the way that it's being used in the
> function, or if i've got something bass ackwards.
> Thanks for your input!
> ~Doc
> --
> www.krushradio.com - Internet Radio for the rest of us

No comments:

Post a Comment