Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

converting integer to varchar in SQL server 2008

Posted on 2010-08-16
2
Medium Priority
?
458 Views
Last Modified: 2012-05-10
i have table data in which there are 3 integer data type columns. i have to convert them to character and insert in to another table.  In the below SQL the two columns in where clause are integer values. I have to convert them 'WO' and 'S':

SELECT [ID]
      ,[OrderNumber]
      ,[OperationsSequenceNumber]
      ,[TransactionCode]
      ,[LogTimeStamp]
      ,[EmployeeID]
      ,[QtyIn]
      ,[QuantityCompleted]
      ,[QuantityRejected]
      ,[Result]
      ,[ReasonID]
      ,[StartTime]
      ,[EndTime]
      ,[WeightingFactor]
      ,[SQLUpdated]
      ,[WoDescription]
      ,[Status]
  FROM [CVDProduction].[dbo].[OperationTransactions]
  WHERE [TransactionCode] = 2
  AND [Status] = 90
GO
0
Comment
Question by:maheshpappu
[X]
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
2 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33450708
You mean something like the following, or is there more to it?
SELECT [ID]
      ,[OrderNumber]
      ,[OperationsSequenceNumber]
      ,'WO'
      ,[LogTimeStamp]
      ,[EmployeeID]
      ,[QtyIn]
      ,[QuantityCompleted]
      ,[QuantityRejected]
      ,[Result]
      ,[ReasonID]
      ,[StartTime]
      ,[EndTime]
      ,[WeightingFactor]
      ,[SQLUpdated]
      ,[WoDescription]
      ,'S'
  FROM [CVDProduction].[dbo].[OperationTransactions]
  WHERE [TransactionCode] = 2
  AND [Status] = 90
GO

Open in new window

0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 33450717
To insert into an existing table:INSERT INTO SomeTable (WO, S)SELECT CONVERT(varchar(100), TransactionCode), CONVERT(varchar(100), Status)FROM [CVDProduction].[dbo].[OperationTransactions]Or to just have your original query create a new table:SELECT [ID]      ,[OrderNumber]      ,[OperationsSequenceNumber]      ,CONVERT(varchar(100), [TransactionCode]) AS WO      ,[LogTimeStamp]      ,[EmployeeID]      ,[QtyIn]      ,[QuantityCompleted]      ,[QuantityRejected]      ,[Result]      ,[ReasonID]      ,[StartTime]      ,[EndTime]      ,[WeightingFactor]      ,[SQLUpdated]      ,[WoDescription]      ,CONVERT(varchar(100), [Status]) AS SINTO NewTableName  FROM [CVDProduction].[dbo].[OperationTransactions]  WHERE [TransactionCode] = 2  AND [Status] = 90
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

610 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