Solved

SQL: Hardcode result in recordset

Posted on 2004-10-01
7
838 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
Comment Utility
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
Comment Utility
>>Please don't ask about the whys or the wherefores!
OK.
WHAT exactly do you mean?
0
 

Author Comment

by:equentin
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Accepted Solution

by:
AntonG earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
So close yet so far!  Thanks.
0
 
LVL 12

Expert Comment

by:pique_tech
Comment Utility
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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 different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

772 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

12 Experts available now in Live!

Get 1:1 Help Now