Hey everyone, I am your usual data person. (E.g. no training whatsoever but somehow working as an analyst in a research firm). For a work project we are using MS SQL Server due to the size of the data tables. OK, fine, another language I have to learn with literally zero time at all to even take a tutorial.
Basically here is the question:
Why am I getting this error "Conversion failed when converting the nvarchar value 'A44434KSH-P02-T03-3113' to data type int."?
The table column it is being placed in is nvarchar 250 and I do not know why it is "converting to data type int". I have a suspicion, but this is my first day using T-SQL.
Here's the code:
USE XXX_DATA_2017
GO
INSERT INTO [dbo].[tbl_Master_Issues](HouseholdID, IssueID, PersonID, TripID, Warning,TestNumber,DateIssueCreated)
**SELECT HouseholdID, PersonID, TripID, **
**'Trip Mode Missing' AS Warning, **
'3113' AS TestNumber,
TripID + '-3113' AS IssueID,
**GETDATE() AS DateIssueCreated **
**FROM [dbo].[tbl_2017_CRD_Trips] **
WHERE ((([dbo].[tbl_2017_CRD_Trips].Mode1) Is Null) AND (([dbo].[tbl_2017_CRD_Trips].FlagForRemoval) Is Null)) OR ((([dbo].[tbl_2017_CRD_Trips].Mode1)=77) AND (([dbo].[tbl_2017_CRD_Trips].Mode1Other) Is Null) AND (([dbo].[tbl_2017_CRD_Trips].FlagForRemoval) Is Null));
Yes, I know it has "TripID + '-3113' AS IssueID" - 'A44434KSH-P02-T03' is a tripID to which I wish to append the IssueID. Thing is, the example of code used on this project I have available uses this same thing:
SELECT
[dbo].[02_PersonsValid].PersonID + '-2514' as IssueID,
So why is that OK for this other analyst's code but not on mine?
The column is nvarchar 255 of SQL_Latin1_General_CP1_CI_AS.
My suspicion is that the "+" makes it think this is an integer calculation, but like I displayed the other analyst has used this formatting. Also, T-SQL rejects "&" saying "The data types nvarchar and varchar are incompatible in the '&' operator." Arg.
So any help would be greatly appreciated!!
Also - WHY DOES MS HAVE MULTIPLE TYPES OF SQL?! Why can they not be made compatible with eachother?
I'm not a coder but have to write in 4 languages to create/maintain a database, so I don't need extra work- but thats just complaining....
Thanks in advance!