Solved

converting integer to varchar in SQL server 2008

Posted on 2010-08-16
2
432 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
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 92

Accepted Solution

by:
Patrick Matthews earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

861 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

29 Experts available now in Live!

Get 1:1 Help Now