Solved

SQL query in VIEW  to return recordset and then Add a Constant

Posted on 2008-06-17
4
317 Views
Last Modified: 2012-05-05
Hello:

I'd like to run a query in SQL View,  and have a recordset returned, then add a constant variable to that set for each Company code. Would I use append function?

Like:
SELECT DISTINCT TOP 100 PERCENT ad_adno, ad_code, ad_rep
FROM         OPENQUERY(mysql, 'select * from cuad') Rowset_1
ORDER BY ad_code, ad_adno

Recordset
      1      4B      JAVIER
      2      4B      JAVIER
      3      4B      JAVIER
        A      4B      JAVIER
Thanks,
Joseph

0
Comment
Question by:CEGE
  • 2
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21806825
simple:
SELECT DISTINCT TOP 100 PERCENT ad_adno, cast( ad_code as varchar(20)) + 'B' , ad_rep 
FROM         OPENQUERY(mysql, 'select * from cuad') Rowset_1
ORDER BY ad_code, ad_adno

Open in new window

0
 
LVL 1

Author Comment

by:CEGE
ID: 21806905
Hello:

No, 4B is the name of the company, what I want to add is the A line, what is returned is 1,2,3,4 and then I want A to be added at the end. Sorry for the mixup.
Thanks,

Joseph
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21806934
something like this:
SELECT DISTINCT cast(ad_adno as varchar(10)), ad_code, ad_rep

FROM         OPENQUERY(mysql, 'select * from cuad') Rowset_1

UNION ALL

SELECT DISTINCT 'A', ad_code, ad_rep

FROM         OPENQUERY(mysql, 'select * from cuad') Rowset_1

ORDER BY 2, 1

Open in new window

0
 
LVL 1

Author Closing Comment

by:CEGE
ID: 31468118
very cool. Thank you. It was right on.
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

867 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

20 Experts available now in Live!

Get 1:1 Help Now