Solved

SQL Server insert query

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
replication - alerts? 4 32
Script to randomly create characters in MS SQL 6 32
Convert SP in a format for debugging 7 30
SqlAdvisor 2016 3 29
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

24 Experts available now in Live!

Get 1:1 Help Now