?
Solved

SQL: Hardcode result in recordset

Posted on 2004-10-01
7
Medium Priority
?
881 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

770 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