Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Dynamic substring in SQL
create table #temp1(CID int, text1 varchar(30), text2 varchar(30),text3 varchar(30),text4 varchar(30)) insert into #temp1 values ('1001','SOP2018010120180203GOK001','SOP201800205',null,null), ('1002','PFK2017100120171005GOK015','PFK2017110120180105GOK015','PFK20181201',null), ('1003','SOP2018010120180203GOK001','SOP20180020520180105GOK015','SOP20180408',null) create table #temp2(CID int, outcome varchar(30)) insert into #temp2 values ('1001','SOP20180020520180206LPS016'), ('1002','PFK2018120120182212PNM015'), ('1003','SOP2018040820180508KLN002') select t1.cid, case when substring(t1.text2,1,12) = substring(t2.outcome,1,12) then (select concat(t1.text1,' ',t2.outcome) ) end from #temp1 t1 join #temp2 t2 on t1.cid = t2.cid drop table #temp1,#temp2
run
|
edit
|
history
|
help
0
Recursion and cte
Microsoft SQL Server T-SQL in 10 mn ~ Lesson 13 Subqueries vers. #5
Find gaps in timesheet data between certain hours
№2
Check Constraints
cms by valli
TestTable
STACK
database size
/Users/svetlanakanevskaa/Downloads/ACDB_LIGHT_MS.sql