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
Solved

Select column name as prifix to row values

Posted on 2013-01-23
6
462 Views
Last Modified: 2013-01-23
Hi all

I have a customer table below.
I need the result to be like the values in table customers result below.

I.e I need to append all the result set with column Name as prefix..
How can I achive this?

Thanks in Advance

Customers Resultcustomers table
0
Comment
Question by:ZURINET
6 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 38809243
You'll need to run a query here. Something like

SELECT 'CustomerID' & CustomerID, 'StoeID' & StoreID,......
FROM yourtable


Kelvin
0
 
LVL 9

Expert Comment

by:sognoct
ID: 38809246
you can use string concatenation

example
select
'[customerID].&[' + convert(nvarchar,CustomerID) + ']' as customerID,
'[storeID].&[' + convert(nvarchar,storeID) + ']' as storeID,
...etc ...
FROM tablename
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38809253
Make sure ALL of the fields you are updating are defined as text in the underlying table and Try this in VBA:

Sub DoThis()
dim rs as DAO.recordset
SET rs = CurrentDB.OpenRecordset
if rs.recordcount = 0 then Exit Sub
do until rs.eof
    rs.Edit
    rs!CustomerID = "[CustomerID].[" & CustomerID & "]"
    rs!StoreID= "[StoreID].[" & StoreID & "]"
    rs!AccountNumber = "[AccountNumber].[" & AccountNumber & "]"
    rs.Update
    rs.MoveNext
Loop
rs.close
set rs = nothing

Open in new window


EDIT:

Sorry - I though this was posted in the Access zone... This assumes you're working with an Access interface.
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 2

Accepted Solution

by:
harshada_sonawane earned 500 total points
ID: 38809255
u can try this

SELECT '[id].&'+ '['+ convert(varchar,id) +']' as id from customer

same way for all columns
0
 

Author Comment

by:ZURINET
ID: 38809276
Hi Hars..
Thanks for the great answer!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38809286
ZURINET,

Did you see the earlier post from 'sognoct' at http:#a38809246 ?

Unless I'm missing something,  the answer you accepted from harshada_sonawane is identical to that earlier response...
0

Featured Post

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.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

839 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