how to get column wise data in a row in sql ?
-
Hi Friends, i have data like this....... number -------------- 123 234 3435 5656 i want to display column wise data in one row like this... number --------------- 123,234,3435,5656 kindly tell me the solution for this? urgent:confused:
-
Hi Friends, i have data like this....... number -------------- 123 234 3435 5656 i want to display column wise data in one row like this... number --------------- 123,234,3435,5656 kindly tell me the solution for this? urgent:confused:
allisha wrote:
i want to display column wise data in one row like this... number --------------- 123,234,3435,5656
Read the data back and format a string appropiately. e.g.
bool isFirst = true;
StringBuilder sb = new StringBuilder();
SqlDataReader reader = myCommand.ExecuteReader();
while(reader.Read())
{
if (isFirst)
isFirst = false;
else
sb.Append(",");
sb.Append(reader.GetInt(0).ToString());
}
string displayResult = sb.ToString();
Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
allisha wrote:
i want to display column wise data in one row like this... number --------------- 123,234,3435,5656
Read the data back and format a string appropiately. e.g.
bool isFirst = true;
StringBuilder sb = new StringBuilder();
SqlDataReader reader = myCommand.ExecuteReader();
while(reader.Read())
{
if (isFirst)
isFirst = false;
else
sb.Append(",");
sb.Append(reader.GetInt(0).ToString());
}
string displayResult = sb.ToString();
Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
hi Colin, first of all thanq but i want to show it in sql. if possible cau u tell me the sol in sql.:confused:
-
Hi Friends, i have data like this....... number -------------- 123 234 3435 5656 i want to display column wise data in one row like this... number --------------- 123,234,3435,5656 kindly tell me the solution for this? urgent:confused:
I think through CURSOR only we can solve this issue. Try the below query.. You can also create one function with this query and get the value back in a single column. DECLARE @OUTPUT NVARCHAR(100), @NAME NVARCHAR(100) DECLARE LAST_CURSOR CURSOR LOCAL SCROLL STATIC FOR ---Here give your select query... SELECT NAME FROM DBT_EMPL_DTL OPEN LAST_CURSOR set @OUTPUT = '' FETCH NEXT FROM LAST_CURSOR INTO @NAME WHILE @@FETCH_STATUS = 0 BEGIN BEGIN set @OUTPUT = @OUTPUT + @NAME +',' END FETCH NEXT FROM LAST_CURSOR INTO @NAME END SET @OUTPUT = LTRIM(@OUTPUT) PRINT @OUTPUT CLOSE LAST_CURSOR DEALLOCATE LAST_CURSOR Cheers,
Shetty
-
Hi Friends, i have data like this....... number -------------- 123 234 3435 5656 i want to display column wise data in one row like this... number --------------- 123,234,3435,5656 kindly tell me the solution for this? urgent:confused: