Solved

SQL: Hardcode result in recordset

Posted on 2004-10-01
7
846 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculated columns 13 60
Returning data in a different format 8 45
SQL joining table to itself to combine rows 5 30
Export import database 4 40
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

930 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

13 Experts available now in Live!

Get 1:1 Help Now