Solved

converting integer to varchar in SQL server 2008

Posted on 2010-08-16
2
431 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
2 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
Comment Utility
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

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.

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now