Solved

converting integer to varchar in SQL server 2008

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

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

695 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