Unix Technical Forum

Match field and return to "1"

This is a discussion on Match field and return to "1" within the SQL Server forums, part of the Microsoft SQL Server category; --> hi..i'm new in sql progaming, i try to make make a query that in table field "match" return to ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:04 PM
neolempires2@gmail.com
 
Posts: n/a
Default Match field and return to "1"

hi..i'm new in sql progaming,
i try to make make a query that in table field "match" return to "1"
if no member record in another table and return to "0" if there is any
record member :

ex
table member:
member id
A 12
B 14


Table Incoming.
member note match
C bla..bla 1
A bla..bla 0
D bla..bla 1
...... ....... .....

can anyone help me please?
D

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:04 PM
Ed Murphy
 
Posts: n/a
Default Re: Match field and return to "1"

neolempires2@gmail.com wrote:

> hi..i'm new in sql progaming,
> i try to make make a query that in table field "match" return to "1"
> if no member record in another table and return to "0" if there is any
> record member :
>
> ex
> table member:
> member id
> A 12
> B 14


You have a table and a column of that table with the same
name? Eww, fix that.

> Table Incoming.
> member note match
> C bla..bla 1
> A bla..bla 0
> D bla..bla 1


Assuming that the Incoming table already has rows with correct data
in all columns except possibly 'match':

update Incoming
set match = 0
where member in (select member from member)

update Incoming
set match = 1
where member not in (select member from member)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:04 PM
Steve Kass
 
Posts: n/a
Default Re: Match field and return to "1"

Something like this should work if there is at
most 1 matching row in the other table:

select
M.member,
M.note,
case when Another.member is null
then 1
else 0 end as match
from member as M
left outer join Another
on Another.member = M.member

If there could be multiple matching rows, you have to do
something that will likely be less efficient:

select
M.member,
M.note,
case when exists (
select * from Another
where Another.member = M.member
) then 1 else 0 end as match
from member as M

-- Steve Kass
-- Drew University
-- http://www.stevekass.com


neolempires2@gmail.com wrote:
> hi..i'm new in sql progaming,
> i try to make make a query that in table field "match" return to "1"
> if no member record in another table and return to "0" if there is any
> record member :
>
> ex
> table member:
> member id
> A 12
> B 14
>
>
> Table Incoming.
> member note match
> C bla..bla 1
> A bla..bla 0
> D bla..bla 1
> ..... ....... .....
>
> can anyone help me please?
> D
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 03:05 PM
neolempires2@gmail.com
 
Posts: n/a
Default Re: Match field and return to "1"

it's work! thx steve.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:08 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com