Solved

SQL: Hardcode result in recordset

Posted on 2004-10-01
7
865 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Accepted Solution

by:
AntonG earned 125 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

840 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