Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL: Hardcode result in recordset

Posted on 2004-10-01
7
Medium Priority
?
887 Views
Last Modified: 2012-08-13
How can I manipulate a recordset value so that a value is persistent?

ie something like:
SELECT "Hi", Name FROM myTable

So the results are:

Hi     Fred
Hi     Bill
Hi     Dave

etc etc...  Please don't ask about the whys or the wherefores!
0
Comment
Question by:equentin
[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
7 Comments
 
LVL 5

Expert Comment

by:hkamal
ID: 12198911
Not sure I understand what you are trying to do. What do you want to be persistent?
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12198932
>>Please don't ask about the whys or the wherefores!
OK.
WHAT exactly do you mean?
0
 

Author Comment

by:equentin
ID: 12198989
I need to do it because I've doing a union query and I need to differentiate between the results that are being joined.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
AntonG earned 500 total points
ID: 12199009
Simply:

SELECT
    'Your Persistent Value' AS PersistentValue,
    Col1,
    Col2
FROM
    dbo.YourTable

in fact, it was exactly like you put it, except use single quotation marks, not double.

SELECT "Hi", Name FROM myTable

should read

SELECT 'Hi', Name FROM myTable

Hope this helps....
0
 
LVL 1

Expert Comment

by:AntonG
ID: 12199016
In that Case....

Select
  'Query1' AS PersistentResult,
  Col1
FROM
  dbo.YourTable1
UNION
Select
  'Query2' AS PersistentResult,
  Col1
FROM
  dbo.YourTable2
0
 

Author Comment

by:equentin
ID: 12199027
So close yet so far!  Thanks.
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12199055
I think I get the basic idea of what you're after, in SQL you'd can "force" a field to display whatever you want through concatenation.  So in your example above, you'd have something like:
SELECT IsNull('Hi ' + Name) AS Greeting FROM MyTable
and every record returned would consist of ONE field:
Greeting
------------
Hi Fred
Hi Bill
Hi Dave

You can expand that idea.  One kind of next step might be to add today's date:
SELECT IsNull('Hi ' + Name + ', today is ' + CAST(GetDate() AS VarChar(11))) AS GreetingDate FROM MyTable
every record returned would again consist of ONE field:
GreetingDate
------------------------------
Hi Fred, today is Oct  1 2004
Hi Bill, today is Oct  1 2004
Hi Dave, today is Oct  1 2004

Is that the idea you had in mind?  If so, hope this helps.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.
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.

618 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