January 21, 2010 at 2:08 am
Hi All,
I want to merge 2 columns between Newline/Carriage return.
For Example..
My table
EmpID | First Name | Last Name
------------------------------
1 | First | Second
2 | chris | cintrella
...
i want Output for the following format...
EmpID | Name
--------------
1 | First
Second
2 | chris
cintrella
...
Please give solution....
warm regards,
Ms.Hema
January 21, 2010 at 3:42 am
If using reporting services this would be possible by using a Matrix / tablix and applying grouping
January 21, 2010 at 4:45 am
Thanks for your Reply.
But I want to get from query O/P
then I need to fill in grid using .NET....
January 21, 2010 at 4:49 am
howabout the unpivot operator ?
January 21, 2010 at 5:19 am
I used the following query...
Select 'chris'+ char(13) + 'cintrella' as Name
But Its work in query result as text.
plz. help me
January 21, 2010 at 5:29 am
another way would be as shown below...
declare @table table (EmpID int, FirstName varchar(45), LastName varchar(45))
insert @table values(1, 'First', 'Second')
insert @table values(2, 'Chris', 'Cintrella')
select empid
,'FirstName' NameType
,FirstName
from @table
union all
select empid
,'LastName' NameType
,LastName
from @table
order by empid, nametype
January 21, 2010 at 6:36 am
I used the following query...
Select 'chris'+ char(13)| + 'cintrella' as Name
But Its work in query result as text.
January 21, 2010 at 6:44 am
Thanks repton,
But I already tried this way.
But I need a single row with New Line in grid
|-----------------------------|
| 1 |Chris |
| Cintrella |
-------------------------------
| 2 |Latha |
| Sen |
-------------------------------
Please give me a solution...
January 21, 2010 at 6:52 am
As far as I am aware SQL will not be able to provide the dataset in the way you require - you would need to handle the display of the resultset within your app...
Could be wrong though - other may be able to advise
January 21, 2010 at 12:25 pm
dave.repton (1/21/2010)
As far as I am aware SQL will not be able to provide the dataset in the way you require - you would need to handle the display of the resultset within your app...Could be wrong though - other may be able to advise
Dave, you are right and wrong at the same time...
Right in terms of your recommendation to have the app dealing with string formatting like this but wrong in terms of SQL capabilities (example below using the sample setup you used).
Even though it's possible to do it using SQL I'd like to know the reason for this kind of data "structure"... @hemasenthu: would you mind sharing the business case?
SELECT cast(EmpID AS varchar(10)) +'|' + FirstName + char(13) + LastName AS 'EmpID | Name'
FROM @table
/* result:
EmpID | Name
----------------
1|First
Second
2|Chris
Cintrella
*/
January 21, 2010 at 10:17 pm
Thanks for your Reply ...
I want the result for above format..
because I need the 2 columns are show in a single column but the 2nd column value is under first column value...
Please give me a solution.
January 21, 2010 at 10:21 pm
Hi all,
Thanks for ur reply.
But i want following format O/P:
Because I want to First column value is in top & 2nd column value is followed by Ist column value on second line. Both Column values are in Single Column.
Please Give me a solution....
I'm awaiting for ur Reply...
January 21, 2010 at 10:22 pm
Hi all,
Thanks for ur reply.
But i want following format O/P:
EmpNoFirstNameLastName
1Kumar Sen
2Roy John
EmpNoName
1Kumar
Sen
2Roy
John
Because I want to First column value is in top & 2nd column value is followed by Ist column value on second line. Both Column values are in Single Column.
Please Give me a solution....
I'm awaiting for ur Reply...
January 22, 2010 at 1:03 am
Excellent Lutz - learn something new everyday...
not thought of putting the results to text
declare @table table (EmpID int, FirstName varchar(45), LastName varchar(45))
insert @table values(1, 'First', 'Second')
insert @table values(2, 'Chris', 'Cintrella')
SELECT cast(EmpID AS varchar(10)) +'|' + FirstName + char(13) + LastName AS 'EmpID | Name'
FROM @table
Meha - the above from Lutz when set to display the result in text will work for you. If you want this as seperate rows I don't know how you would achieve this without including extra columns - again, I'd be looking for the apps to handle this I think.
January 22, 2010 at 1:49 am
But I want to show the 2nd column value in next line
Otherwise i want to show the differentiate 1st column & 2nd column value in single column..
Is it possible in .NET Grid...
Please give me a solution...
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply