Bogaso
Bogaso

Reputation: 3308

Select all columns but change a column to string

In Sql, if I want to fetch all columns from a table then I would write select * from <table name>. However let say there is a column called XYZ and type is numeric. However I want to fetch all columns but change that XYZ column to sting, then how should one proceed?

Any help will be highly appreciated.

Upvotes: 2

Views: 3178

Answers (3)

Zanyar Jalal
Zanyar Jalal

Reputation: 1874

SELECT CAST(column AS NVARCHAR(25)) AS xyz_string 
FROM Table

Upvotes: 0

Jason Wadsworth
Jason Wadsworth

Reputation: 8887

I don't think there is a way to do it without either specifying all the columns or duplicating the one you want to convert.

SELECT *, CAST(XYZ as varchar) as XYZ_String
FROM <table>

Upvotes: 0

Tanner
Tanner

Reputation: 2421

Select the other columns individually, and CAST(xyz AS NVARCHAR)

SELECT foo, bar, CAST(xyz AS NVARCHAR)
FROM myTable

Upvotes: 2

Related Questions