Solved

SQL Server Construct a view

Posted on 2011-09-08
2
263 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
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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

749 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