Solved

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

Posted on 2008-06-17
4
316 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

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.
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
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

760 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

18 Experts available now in Live!

Get 1:1 Help Now