I have a total of three sql commands running on one connection. When the query is run, everything works perfectly except one tiny thing. The UNION SELECT on the last command will not attach the ‘TEXT’ on the end of the last statement.
SqlCommand commandtwo = new SqlCommand("SELECT PID = RIGHT(REPLICATE('0',8) + CAST(PID AS VARCHAR(8)),8) + ',' FROM dbo.MDRMASTER WHERE PARENTPID = @PARENTPID UNION SELECT 'TEXT'", con);
SqlCommand commandthree = new SqlCommand("SELECT INST = INST + ',' FROM dbo.MDRMASTER WHERE PARENTPID = @PARENTPID UNION SELECT 'TEXT'", con);
I find this very strange because commandtwo works just fine. I also found it strange that in order for the commas to work in commandthree, I had to write
= INST + ','
instead of just
+ ','
So why am I having these strange occurrences? Or since I consider myself a beginner what is this rule I obviously dont know? Im using SQL Server 2008 R2 Thank you so much.
What’s the data type of
INST?CAST(INST AS nvarchar) + ','might work.