Solved

SQL Server insert query

Posted on 2011-09-19
3
255 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
[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
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
domain login has permission in database, but gets error 3 26
Stored Proc - Rewrite 42 73
Can I skip a node in XML? 9 35
SQL Select Query help 1 38
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.

733 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