Solved

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

Posted on 2008-06-17
4
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 143

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 143

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

688 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