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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Function Return Name

Author  Topic 

mario_2013
Starting Member

3 Posts

Posted - 2013-07-05 : 11:02:00
Help,

Does anyone have a function that performs the
comparison between the existing names in a table and the existing name in table B.And its inclusion in the select?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-05 : 11:47:32
Can you show with an example what you mean? Perhaps one of these?
--- gives you list of names that are in TABLEA but  not in 
-- TABLEB. You can swap TABLEA and TABLEB to find those
-- that are in TABLEB, but not in TABLEA.
SELECT name FROM TABLEA
EXCEPT
SELECT name FROM TableB;

-- gives you the list of names that are in both tables.
SELECT name FROM TABLEA
INTERSECT
SELECT name FROM TABLEB;

-- gives you list of names from both table, but only once
-- if the name is in both tables.
SELECT name FROM TABLEA
UNION
SELECT name FROM TABLEB;
Go to Top of Page

mario_2013
Starting Member

3 Posts

Posted - 2013-07-05 : 12:38:22
Example ... if you want to compare in Table D customer name 'Anderson' is equal to the customer name in table D. If yes then return the customer name but not write the record
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-05 : 13:07:48
quote:
Originally posted by mario_2013

Example ... if you want to compare in Table D customer name 'Anderson' is equal to the customer name in table D. If yes then return the customer name but not write the record

I am afraid that is not making any sense to me. If customer name "Anderson" is in TableD, and if you compare it against customer name "Anderson" in TableD, it is always going to return true if the name is in there.

From your orignal post, I thought you were trying to compare data in two tables. This sounds like you are trying to compare the data in a single table.

Or, are you trying to send in a name as a parameter and test if that name is in the table?

Take a look at this blog - it might help you formulate the question in a manner that is easier for others to understand: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -