Suppose I have 2 tables in sql2008
create table table1 (
location varchar(10),
facility varchar(10),
msgid int,
col5 varchar(20)
)
create table table2 (
msgid int,
name varchar(10),
col3 varchar(20),
col4 varchar(20)
)
insert into table1 (msgid, location, facility, col5)
select 1, 'F1', 'L1', 'xyz'
union select 2, 'F1', L1', 'abc'
union select 3, 'F1', L1', 'abcd'
union select 4, 'F1', L2', 'abce'
union select 5, 'F2', L1', 'abcf'
insert into table2 (msgid, name, col3, col4)
select 1, 'x', 'dsd','fwefrwe'
union select 2, 'x', 'dsd1','fwefrwe1'
union select 3, 'y', 'dsd2','fwefrwe2'
union select 4, 'z', 'dsd3','fwefrwe3'
union select 5, 'a', 'dsd4','fwefrwe4'
Suppose I want to yield the following result
select col3,col4,col5 from table1 inner join table2 where name+'^'+facility+'^'+location in ('x^F1^L1', 'z^F1^L2')
I understand concatenate the string like this is one of the worst thing to do, but can I ask if there is a more elegant way to optimize this statement and can be use in Dapper?
Many thanks