Solved

SQL Server Construct a view

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

919 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

19 Experts available now in Live!

Get 1:1 Help Now