Solved

SQL Server Construct a view

Posted on 2011-09-08
2
257 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
Comment Utility
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
Comment Utility
It worked. Thank you
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now