¾È±Ô °øºÎ¹æ

MS-SQL > UPDATE - ÀÚ·á ¼öÁ¤

µî·ÏÀÏ : 2017-06-30 16:58 Á¶È¸¼ö : 53,801

1. ±âº»¹®¹ý

NUMBER ÇʵåÀÇ °ªÀÌ 1 ÀÎ ·¹Äڵ忡 À̸§Çʵ忡 'Ã־ȱÔ' ID Çʵ忡 'CAK0280' °ªÀ» ³Ö¾î¶ó.

UPDATE Å×À̺í¸í set name='Ã־ȱÔ',id='CAK0280' WHERE NUMBER=1

2. STUFF() , SUBSTRING() À» ÀÌ¿ëÇÑ ¾÷µ¥ÀÌÆ®

update Äõ¸®¿Í STUFF ÇÔ¼ö¿Í SUBSTRINGÇÔ¼ö¸¦ ÀÌ¿ëÇÏ´Â ¹æ¹ýÀ» ¾Ë¾Æº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.....

´ÙÀ½°ú °°Àº °æ¿ì°¡ ÀÖ´Ù°í °¡Á¤À» ÇØ º¸°Ú½À´Ï´Ù.

Å×À̺í¸í : TEST

board_idx

 NUM

1

001001

2

001002

3

001003

4

000004

5

000005


À§ÀÇ Å×À̺íó·³ TEST Å×ÀÌºí¿¡ NUM Çʵ尡 001001 ó·³ µÇ¾î ÀÖ½À´Ï´Ù.

¸¸¾à µÎ¹ø° °ª¿¡¼­ ºÎÅÍ 2°³ ¹®ÀÚ°¡ '01' ·Î µÇ¾î ÀÖ´Â °ªÀ» '00' À¸·Î ÀÏ°ýµÇ°Ô ¼öÁ¤ÇÏ°í ½ÍÀ¸½Ã¸é ¾î¶»°Ô ÇϽðڽÀ´Ï´Ù.

Áï, ¾Æ·¡ ±¸Á¶Ã³·³ ¹Ù²î°Ô µÇ´Â°Ì´Ï´Ù.

Å×À̺í¸í : TEST

board_idx

 NUM

1

000001

2

000002

3

000003

4

000004

5

000005


FROM ¹®¿¡ SUBQUERY ¸¦ »ç¿ëÇÏ°í, STUFF ÇÔ¼ö¿Í SUBSTRINGÇÔ¼ö¸¦ ÀÌ¿ëÇϸé ÇØ°áÇϽǼö ÀÖ½À´Ï´Ù.

¾Æ·¡ÀÇ Äõ¸®Ã³·³ ÇÏ½Ã¸é µË´Ï´Ù.

UPDATE test SET num= STUFF(num,2,2,'01') where substring(num,2,2)='01'

STUFF ÇÔ¼ö´Â ƯÁ¤À§Ä¡ÀÇ °ªÀ» ¹Ù²Ù¾î ÁÙ¼ö ÀÖ½À´Ï´Ù.

STUFF(¹®ÀÚ, ½ÃÀÛÀ§Ä¡, ±æÀÌ, ¹Ù²Ü¹®ÀÚ)

NUM Çʵ忡¼­ 2¹ø° ¹®ÀÚ¿¡¼­ 2°³¸¦ °¡Áö°í ¿Í¼­ 00À¸·Î ¹Ù²Ù¾î ÁÝ´Ï´Ù.
WHERE ¹®¿¡¼­ SUBSTRING(NUM,2,2)='01' Á¶°ÇÀ» º¸¸é ¾Æ½Ã°ÚÁö¸¸, 01 °ªÀ» °¡Áö°í ¿Í¼­ ƯÁ¤À§ÀÇ ¹®ÀÚ¸¦ ¹Ù²Ù¾î ÁÖ¸é µË´Ï´Ù. 

3. ÀÏ°ý UPDATE

update customer_goods SET c_name = customer.c_name, c_type=customer.c_type, 
c_jumin1=customer.c_jumin1, c_jumin2=customer.c_jumin2 , c_office_no=customer.c_office_no, 
c_zipcode1=customer.c_zipcode1, c_address=customer.c_address,c_zipcode2=customer.c_zipcode2, 
c_tel1=customer.c_tel1, c_tel2=customer.c_tel2, c_tel3=customer.c_tel3, c_email=customer.c_email, 
c_bigo=customer.c_bigo, c_jumin_date=customer.c_jumin_date FROM customer INNER JOIN customer_goods 
ON customer_goods.g_custom_idx = customer.custom_idx

3. Replace() ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ ÀϺκР¾÷µ¥ÀÌÆ®

µ¥ÀÌÅÍ Ä®·³¿¡ AAA ¶û ¹®ÀåÀÌ ÀÖÀ» °æ¿ì, ¸ðµÎ BBB ·Î ¼öÁ¤À» ÇÏ°í ½ÍÀ» °æ¿ì Replace ÇÔ¼ö¸¦ ÀÌ¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.

Update board set title=replace(title,'AAA','BBB') where Á¶°Ç

À§¿Í °°Àº Çü½ÄÀ¸·Î ÇÏ½Ã¸é µË´Ï´Ù.

À§ÀÇ Å×À̺íÀÇ Çʵå´Â Varchar Çü À϶§¸¸ °¡´ÉÇÕ´Ï´Ù. Text , nText Çü¿¡¼­´Â ¿¡·¯¸¦ ¹ß»ýÇÕ´Ï´Ù.

replace ÇÔ¼öÀÇ 1 Àμö¿¡ ´ëÇÑ Àμö µ¥ÀÌÅÍ Çü½Ä ntextÀÌ(°¡) À߸øµÇ¾ú½À´Ï´Ù. À§¿Í °°Àº ¿¡·¯¸¦ ¹ß»ýÇÕ´Ï´Ù.

ÀÌ·±°æ¿ì Ä®·³À» varchar ÇüÀ¸·Î ¹Ù²Û ÈÄ ÀÌ¿ëÇÏ¸é µË´Ï´Ù.

Update board set content=replace(convert(varchar(8000),content),'AAA','BBB') where Á¶°Ç

À§¿Í °°Àº Çü½ÄÀ¸·Î convert ÇÔ¼ö¸¦ ÀÌ¿ëÇؼ­ Çü½ÄÀ» ¹Ù²Ù¾î ÁÝ´Ï´Ù.
varchar ÇüÀ¸·Î µÇ¾î ÀÖ´Â Çʵå , µ¥ÀÌÅÍ °ªÀº '2012-12-30 ¿ÀÀü 12:00' ¿Í °°Àº Çü½ÄÀ¸·Î µÇ¾î ÀÖ´Â °æ¿ì, Datetime ÇüÀ¸·Î º¯È¯½ÃÅ°¸é ¿¡·¯°¡ ³­´Ù.
ÀÌ·²°æ¿ì '2012-12-30 12:00' °°Àº ÇüÅ·Π¹Ù²Ù¾î¼­ µðºñ ¸¶À̱׷¹À̼ÇÀ» ÇØ¾ß ÇÑ´Ù. ÀÌ·±°æ¿ì substringÀ» ÀÌ¿ëÇÏ¸é µÇ´Âµ¥, Äõ¸®´Â ¾Æ·¡¿Í °°´Ù.

writeday (varchar) --> writeday1 (datetime) À¸·Î º¯È¯½ÃŲ´Ù.

update areum_board1 set writeday1=dateadd(mm,1,substring(writeday,1,10) + substring(writeday,14,9) + case substring(writeday,12,2) when '¿ÀÀü' then 'AM' else 'PM' end)
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.