Home All Groups Group Topic Archive Search About

Trouble using Table data type

Author
28 Jul 2005 11:30 AM
João Costa
hello, I'm using Table data type as a suggestion to lower Stack use. I'm just
having trouble figuring out how to use the table var correctly.

1    update @MDMB
2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
3    from @MDMBTotaisAssoc BIT
4    where BIT.MRCSKA = '-'          and
5            @MDMB.MRCUIC = BIT.MRCUIC 

I get an error in line 2:

Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
Line 2: Incorrect syntax near '.'.

Thanks in advance

Author
28 Jul 2005 11:38 AM
Subramaniam Sivakumar
Try like this

1    update @MDMB
2    set MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
3    from @MDMBTotaisAssoc BIT
4    where BIT.MRCSKA = '-'          and
5            @MDMB.MRCUIC = BIT.MRCUIC 

OR

1    update @MDMB
2    set MDMBMT = MDMBMT - BIT.MDMBMT
3    from @MDMBTotaisAssoc BIT
4    where BIT.MRCSKA = '-'          and
5            @MDMB.MRCUIC = BIT.MRCUIC 


Regards
Sivakumar


Show quote
"João Costa" wrote:

> hello, I'm using Table data type as a suggestion to lower Stack use. I'm just
> having trouble figuring out how to use the table var correctly.
>
> 1    update @MDMB
> 2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> 3    from @MDMBTotaisAssoc BIT
> 4    where BIT.MRCSKA = '-'          and
> 5            @MDMB.MRCUIC = BIT.MRCUIC 
>
> I get an error in line 2:
>
> Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
> Line 2: Incorrect syntax near '.'.
>
> Thanks in advance
>
>
>
Author
28 Jul 2005 12:01 PM
João Costa
Tryed both ways, it didn't work I got the message:

Must declare the variable '@MDMB'.
in the first case for line 2 in the second case for line 5

tryied a third case
1  update @MDMB
2    set MDMBMT = MDMBMT - BIT.MDMBMT
3    from @MDMBTotaisAssoc BIT
4      where BIT.MRCSKA = '-'          and
5            MRCUIC = BIT.MRCUIC

I got 2 messages:
Ambiguous column name 'MDMBMT'.
Ambiguous column name 'MRCUIC'.

Show quote
"Subramaniam Sivakumar" wrote:

> Try like this
>
> 1    update @MDMB
> 2    set MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> 3    from @MDMBTotaisAssoc BIT
> 4    where BIT.MRCSKA = '-'          and
> 5            @MDMB.MRCUIC = BIT.MRCUIC 
>
> OR
>
> 1    update @MDMB
> 2    set MDMBMT = MDMBMT - BIT.MDMBMT
> 3    from @MDMBTotaisAssoc BIT
> 4    where BIT.MRCSKA = '-'          and
> 5            @MDMB.MRCUIC = BIT.MRCUIC 
>
>
> Regards
> Sivakumar
>
>
> "João Costa" wrote:
>
> > hello, I'm using Table data type as a suggestion to lower Stack use. I'm just
> > having trouble figuring out how to use the table var correctly.
> >
> > 1    update @MDMB
> > 2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> > 3    from @MDMBTotaisAssoc BIT
> > 4    where BIT.MRCSKA = '-'          and
> > 5            @MDMB.MRCUIC = BIT.MRCUIC 
> >
> > I get an error in line 2:
> >
> > Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
> > Line 2: Incorrect syntax near '.'.
> >
> > Thanks in advance
> >
> >
> >
Author
28 Jul 2005 12:11 PM
ML
The alias defined in the FROM clause must be used in the entire UPDATE
statement.


ML
Author
28 Jul 2005 12:18 PM
João Costa
Did that and got the message:
Cannot use the column prefix 'X'. This must match the object in the UPDATE
clause '@MDMB'.
and if I use the prefix @MDMB I get an error also

Any Ideas anyone?

Show quote
"ML" wrote:

> The alias defined in the FROM clause must be used in the entire UPDATE
> statement.
>
>
> ML
Author
28 Jul 2005 1:06 PM
ML
Subramaniam used 'BIT' as the alias, not 'X'.


ML
Author
28 Jul 2005 1:27 PM
João Costa
Yes but I also tried the x on my own, sorry for not mentioning


Show quote
"ML" wrote:

> Subramaniam used 'BIT' as the alias, not 'X'.
>
>
> ML
Author
28 Jul 2005 1:52 PM
ML
I'll have to see your query to help you further.


ML
Author
28 Jul 2005 11:40 AM
Narayana Vyas Kondreddi
See if this helps:

UPDATE @MDMB
SET MDMBMT = MDMBMT - [BIT].MDMBMT
from @MDMB AS X
INNER JOIN
@MDMBTotaisAssoc  AS [BIT]
ON [BIT].MRCSKA = '-'
AND X.MRCUIC = [BIT].MRCUIC

You should use an alias for column names when using table variables.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


"João Costa" <JooCo***@discussions.microsoft.com> wrote in message
news:977CB913-3E0F-48DD-AAD7-F4084A4B6857@microsoft.com...
hello, I'm using Table data type as a suggestion to lower Stack use. I'm
just
having trouble figuring out how to use the table var correctly.

1    update @MDMB
2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
3    from @MDMBTotaisAssoc BIT
4    where BIT.MRCSKA = '-'          and
5            @MDMB.MRCUIC = BIT.MRCUIC

I get an error in line 2:

Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
Line 2: Incorrect syntax near '.'.

Thanks in advance
Author
28 Jul 2005 12:20 PM
João Costa
Didn't work

Show quote
"Narayana Vyas Kondreddi" wrote:

> See if this helps:
>
> UPDATE @MDMB
> SET MDMBMT = MDMBMT - [BIT].MDMBMT
>  from @MDMB AS X
> INNER JOIN
> @MDMBTotaisAssoc  AS [BIT]
>  ON [BIT].MRCSKA = '-'
> AND X.MRCUIC = [BIT].MRCUIC
>
> You should use an alias for column names when using table variables.
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
>
>
> "João Costa" <JooCo***@discussions.microsoft.com> wrote in message
> news:977CB913-3E0F-48DD-AAD7-F4084A4B6857@microsoft.com...
> hello, I'm using Table data type as a suggestion to lower Stack use. I'm
> just
> having trouble figuring out how to use the table var correctly.
>
> 1    update @MDMB
> 2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> 3    from @MDMBTotaisAssoc BIT
> 4    where BIT.MRCSKA = '-'          and
> 5            @MDMB.MRCUIC = BIT.MRCUIC
>
> I get an error in line 2:
>
> Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
> Line 2: Incorrect syntax near '.'.
>
> Thanks in advance
>
>
>
>
>
Author
28 Jul 2005 12:27 PM
Narayana Vyas Kondreddi
Try this:
UPDATE @MDMB
SET MDMBMT = X.MDMBMT - [BIT].MDMBMT
from @MDMB AS X
INNER JOIN
@MDMBTotaisAssoc  AS [BIT]
ON [BIT].MRCSKA = '-'
AND X.MRCUIC = [BIT].MRCUIC

--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


"João Costa" <JooCo***@discussions.microsoft.com> wrote in message
news:D64F080D-1F34-4EFB-BBF4-FC9E1E13B362@microsoft.com...
Didn't work

Show quote
"Narayana Vyas Kondreddi" wrote:

> See if this helps:
>
> UPDATE @MDMB
> SET MDMBMT = MDMBMT - [BIT].MDMBMT
>  from @MDMB AS X
> INNER JOIN
> @MDMBTotaisAssoc  AS [BIT]
>  ON [BIT].MRCSKA = '-'
> AND X.MRCUIC = [BIT].MRCUIC
>
> You should use an alias for column names when using table variables.
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
>
>
> "João Costa" <JooCo***@discussions.microsoft.com> wrote in message
> news:977CB913-3E0F-48DD-AAD7-F4084A4B6857@microsoft.com...
> hello, I'm using Table data type as a suggestion to lower Stack use. I'm
> just
> having trouble figuring out how to use the table var correctly.
>
> 1    update @MDMB
> 2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> 3    from @MDMBTotaisAssoc BIT
> 4    where BIT.MRCSKA = '-'          and
> 5            @MDMB.MRCUIC = BIT.MRCUIC
>
> I get an error in line 2:
>
> Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
> Line 2: Incorrect syntax near '.'.
>
> Thanks in advance
>
>
>
>
>
Author
28 Jul 2005 1:36 PM
João Costa
It does compile, it seems that the problem is passed. I will debug and I'll
let you know

Thanks Narayana!

Show quote
"Narayana Vyas Kondreddi" wrote:

> Try this:
> UPDATE @MDMB
> SET MDMBMT = X.MDMBMT - [BIT].MDMBMT
>  from @MDMB AS X
> INNER JOIN
> @MDMBTotaisAssoc  AS [BIT]
>  ON [BIT].MRCSKA = '-'
> AND X.MRCUIC = [BIT].MRCUIC
>
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
>
>
> "João Costa" <JooCo***@discussions.microsoft.com> wrote in message
> news:D64F080D-1F34-4EFB-BBF4-FC9E1E13B362@microsoft.com...
> Didn't work
>
> "Narayana Vyas Kondreddi" wrote:
>
> > See if this helps:
> >
> > UPDATE @MDMB
> > SET MDMBMT = MDMBMT - [BIT].MDMBMT
> >  from @MDMB AS X
> > INNER JOIN
> > @MDMBTotaisAssoc  AS [BIT]
> >  ON [BIT].MRCSKA = '-'
> > AND X.MRCUIC = [BIT].MRCUIC
> >
> > You should use an alias for column names when using table variables.
> > --
> > HTH,
> > Vyas, MVP (SQL Server)
> > SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
> >
> >
> > "João Costa" <JooCo***@discussions.microsoft.com> wrote in message
> > news:977CB913-3E0F-48DD-AAD7-F4084A4B6857@microsoft.com...
> > hello, I'm using Table data type as a suggestion to lower Stack use. I'm
> > just
> > having trouble figuring out how to use the table var correctly.
> >
> > 1    update @MDMB
> > 2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> > 3    from @MDMBTotaisAssoc BIT
> > 4    where BIT.MRCSKA = '-'          and
> > 5            @MDMB.MRCUIC = BIT.MRCUIC
> >
> > I get an error in line 2:
> >
> > Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
> > Line 2: Incorrect syntax near '.'.
> >
> > Thanks in advance
> >
> >
> >
> >
> >
>
>
>
Author
28 Jul 2005 11:44 AM
Roji. P. Thomas
You MUST use an alias when referring a table variable in a JOIN.

See
http://toponewithties.blogspot.com/2004/08/difference-between-table-variable-and.html


--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com


Show quote
"João Costa" <JooCo***@discussions.microsoft.com> wrote in message
news:977CB913-3E0F-48DD-AAD7-F4084A4B6857@microsoft.com...
> hello, I'm using Table data type as a suggestion to lower Stack use. I'm
> just
> having trouble figuring out how to use the table var correctly.
>
> 1    update @MDMB
> 2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> 3    from @MDMBTotaisAssoc BIT
> 4    where BIT.MRCSKA = '-'          and
> 5            @MDMB.MRCUIC = BIT.MRCUIC
>
> I get an error in line 2:
>
> Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
> Line 2: Incorrect syntax near '.'.
>
> Thanks in advance
>
>
>
Author
28 Jul 2005 12:24 PM
João Costa
Ok, I'm trying that, do you have some ideas on the sintax?

Show quote
"Roji. P. Thomas" wrote:

> You MUST use an alias when referring a table variable in a JOIN.
>
> See
> http://toponewithties.blogspot.com/2004/08/difference-between-table-variable-and.html
>
>
> --
> Roji. P. Thomas
> Net Asset Management
> https://www.netassetmanagement.com
>
>
> "João Costa" <JooCo***@discussions.microsoft.com> wrote in message
> news:977CB913-3E0F-48DD-AAD7-F4084A4B6857@microsoft.com...
> > hello, I'm using Table data type as a suggestion to lower Stack use. I'm
> > just
> > having trouble figuring out how to use the table var correctly.
> >
> > 1    update @MDMB
> > 2    set @MDMB.MDMBMT = @MDMB.MDMBMT - BIT.MDMBMT
> > 3    from @MDMBTotaisAssoc BIT
> > 4    where BIT.MRCSKA = '-'          and
> > 5            @MDMB.MRCUIC = BIT.MRCUIC
> >
> > I get an error in line 2:
> >
> > Server: Msg 170, Level 15, State 1, Procedure PCRMMRCQ00vInt, Line 2
> > Line 2: Incorrect syntax near '.'.
> >
> > Thanks in advance
> >
> >
> >
>
>
>

AddThis Social Bookmark Button