Solved

SQL Server insert query

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

11 Experts available now in Live!

Get 1:1 Help Now