know which column result was from

thejeraldo

Well-known member
Joined
Jun 9, 2009
Messages
70
Location
Philippines
Programming Experience
1-3
hey guys is there any way on how to know which column a result from an SQL Like statement belongs to. say for example my SQL is:

SELECT lastname,firstname from EMPLOYEES where lastname LIKE 'Ro%' or firstname LIKE 'Ro%'

then if the results are: Rooney, Ronaldo, Roberto
from a table that looks like this

lastname | firstname
--------------------
Rooney | Wayne
Ronaldo | Cristiano
Carlos | Roberto

i wanna my program to know that the results
Ronaldo & Rooney is from the column from my dataset Lastname
Roberto is from the column from my dataset Firstname.

thanks guys!
 
Aren't you already going to know this because they're in the respective first and last name columns in your dataset?
 
what i mean is that.. i want to know which field returned the result for a certain result... ahm... (kinda hard to explain) its kinda like this:

SELECT lastname,firstname from EMPLOYEES where lastname LIKE 'Ro%' or firstname LIKE 'Ro%'

lastname | firstname
--------------------
Rooney | Wayne->in this record, lastname col was used to return result from the SQL statement.
Ronaldo | Cristiano
Carlos | Robertoin this record, firstname col was used to return result from the SQL statement.
 
Oracle syntax

VB.NET:
SELECT
  firstname,
  lastname,
  CASE WHEN firstname like :param THEN 'FIRST' ELSE 'LAST' END as whichcol
FROM
  footballers
WHERE
  firstname like :param OR lastname LIKE :param

Adjust it to your db. Results:


Rooney | Wayne | LAST
Ronaldo | Cristiano | LAST
Carlos | Robertoin | FIRST
 

Latest posts

Back
Top