Solved

SQL Server insert query

Posted on 2011-09-19
3
243 Views
Last Modified: 2012-05-12
INSERT INTO [DBNAME].[dbo].[PART]
           ([ID]
           ,[DESCRIPTION]
SELECT [ID] & '-RG' AS Expr1
      ,[DESCRIPTION]
From OTHERDB.dbo.Part

So the key is adding the -RG to the end of the ID field from the otherdb which as the query stands gives me:

Msg 402, Level 16, State 1, Line 147
The data types varchar and varchar are incompatible in the '&' operator.
0
Comment
Question by:MyDanes
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
carsRST earned 500 total points
ID: 36561710
SQL Server uses the "+" sign for concatenation.
Take out the "&" and replace with "+"
0
 
LVL 16

Expert Comment

by:carsRST
ID: 36561746
Also you may need to use the CAST function if you get another error.

something like this...


INSERT INTO [DBNAME].[dbo].[PART]
           ([ID]
           ,[DESCRIPTION]
SELECT CAST([ID] as varchar(5)) + '-RG' AS Expr1
      ,[DESCRIPTION]
From OTHERDB.dbo.Part
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 36561772
hello, you can not store string into int datatype you should take one more field for save this ID and store with -RG into this field.
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.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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