Solved

SQL Server Construct a view

Posted on 2011-09-08
2
264 Views
Last Modified: 2012-05-12
I have 2 tables in sql server 2005.
Table A has a field 'main_code' and table B has two fields 'main_code' and 'barcode'. The tables have a relationship on the 'main_code' fields.
I need to construct a view that for each record in B will display the 'barcode' field. In case there is no record from table A associated to table B (in other words the product has no barcode) I want to display the 'main_code' field.
0
Comment
Question by:delimpasis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
Anna_R earned 50 total points
ID: 36501515
select A.main_code, case when B.barcode is null then A.main_code else B.barcode end 'my column'
from A
left join B on (A.main_code=B.main_code)
0
 

Author Closing Comment

by:delimpasis
ID: 36501759
It worked. Thank you
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question