반응형

[MSSQL] 테이블 두 개 사용해서 select 된 값 바로 update하기

 



1. 먼저 현재값과 update해야할 값을 조회해본다.

select a.컬럼1, b.컬럼1
   ,a.컬럼2, b.컬럼2
   ,a.컬럼3, b.컬럼3
   ,a.컬럼4, b.컬럼4
FROM 테이블1 a inner join 테이블2 b on a.컬럼1 =b.컬럼2 and a.컬럼1_1=b.컬럼2_2
where a.컬럼 = 조건



2. ,을 =로 바꾸주고 바로 update 해준다.

update a set a.컬럼1 = b.컬럼1
   ,a.컬럼2 = b.컬럼2
   ,a.컬럼3 = b.컬럼3
   ,a.컬럼4 = b.컬럼4
FROM 테이블1 a inner join 테이블2 b on a.컬럼1 =b.컬럼2 and a.컬럼1_1=b.컬럼2_2
where a.컬럼 = 조건



반응형
반응형

[MSSQL]  STRING_SPLIT(Transact-SQL)

https://learn.microsoft.com/ko-kr/sql/t-sql/functions/string-split-transact-sql?view=sql-server-ver16 

 

STRING_SPLIT(Transact-SQL) - SQL Server

STRING_SPLIT 함수의 Transact-SQL 참조입니다. 이 테이블 반환 함수는 문자 구분 기호를 기준으로 문자열을 부분 문자열로 분할합니다.

learn.microsoft.com

지정된 구분 기호 문자에 따라 문자열을 부분 문자열의 행으로 분할하는 테이블 반환 함수입니다.

SELECT ProductId, Name, Tags  
FROM Product  
JOIN STRING_SPLIT('1,2,3',',')
    ON value = ProductId;

 

 

반응형
반응형

update select 로 json data 변경하기

 

json_value, json_modify

-- update select 로 json data 변경하기 

 UPDATE AA  SET 
        AA.컬럼1 = JSON_MODIFY(BB.컬럼1,'$.must.title_inner',JSON_VALUE(BB.컬럼1, '$.must.title'))  
   from Table01 AS AA, Table01 AS BB 
  where BB.key = AA.KEY 
    

위 update문 옆에는 Alias로 배치하고 나머지 쿼리를 해보면 된다. 

 

일단 update 전에 select로 데이터 테스트는 필수!!!

 

잘못하면 훅! 간다~ 

반응형
반응형

[MYSQL] update ...select 구문. 삽질하다가 OK

#mysql #database #update #select

아래처럼 해야함.

update wp_moa_bible_mcheyne m

  join wp_moa_bible_sort s on s.name_short = m.sort_name

   set m.ever_seq_no = s.ever_seq_no

;

아래처럼 계속 하면 삽질만 한다. 

update wp_moa_bible_mcheyne a

set ever_seq_no = (

    select ever_seq_no

      from wp_moa_bible_sort b

    where a.sort_name = b.name_short

);



update wp_moa_bible_mcheyne m,

        wp_moa_bible_sort s

    set m.ever_seq_no = s.ever_seq_no

  where m.sort_name = s.sort_name

;
반응형
반응형

http://igor10k.github.io/ikSelect/

 

Stylize selects across all browsers with little effort.

 

Features

  • custom syntax support
  • works perfect as an inline-block
  • no z-index bugs in IE
  • optgroups support
  • great API
  • add/remove <option>'s and <optgroup>'s
  • disable/enable anything (select, optgoup, option)
  • optional filter text field
  • can be used with hidden parents
  • compatible with mobile devices
  • behavior is as authentic as possible
  • callbacks and event triggers
  • automatic calculations
    • dropdown position, so it's always visible when opened
    • needed width for the select or it's dropdown (can be disabled)
    • active option appears in the center of the opened dropdown
  • keyboard support
    • search by letters/numbers/etc
    • navigation
    • tab and shift+tab
  • fast and easy to use
  • built with attention to details
  • according to the poll, 100% of people love it*
    *of all the five friends I asked
반응형

+ Recent posts