Home > database >  SQL related issues
SQL related issues

Time:11-23


As is shown in
Group two good data as compared Years fields with a group they are included and contained relationship contained Issn values need to be modified into No
Online for bosses to solve thank you!!!!!!

CodePudding user response:

 if OBJECT_ID (' tempdb for.. # # Table_1 ') is not null drop table Table_1 
The create table # Table_1 (Title nvarchar (2), Issn nvarchar (Max), Years nvarchar (Max))

Insert into # Table_1 (Title, Issn, Years) (
Select the Title 'aa', '1231 -' 1233 Issn, ', 2013201 'Years union all
Select the Title 'aa', '1231 -' 1233 Issn, ', 2013201, 4201, 5201 (6) Years union all
Select the Title 'bb', '1231 -' 1233 Issn, '8, 2013201, 4201, 7201 Years union all
Select the Title 'bb', '1231 -' 1233 Issn, '8' 2017201 Years
)

Update # Table_1 set Issn='No' from # Table_1 where a
The exists (select from 1 # Table_1 b where a.T itle=b.T itle and a.Y ears<> B.Y ears and
CHARINDEX (a.Y ears, b.Y ears) & gt; 0)

/* the results
Aa No 2013201
Aa 1231-1233, 2013201, 4201, 5201 (6)
Bb, 1231-1233, 2013201, 4201, 7201 8
Bb No 8 2017201
*/
  • Related