SQLȡֵÎÊÌâ - MS-SQL Server / »ù´¡Àà
±ítable
A B
12*2+10*5
4*3+10*4
15*2+81*4
ÈçºÎÈ¡BÁÐÖеÚÒ»¸ö*ºÅǰµÄÊý£¬²¢¸³¸øAÁÐ
--search
SQL code:
select left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1)
--update
SQL code:
update table
set a = left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1)
select left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1) > 0
update table set a = left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1) > 0
SQL code:
update ±ítable set A=left(B,charindex('*',B)-1)
¶¼ÊÇÅ£È˰¡¡£
û¶àÉÙ·Ö£¬ºÇºÇ£¬È¨µ±Òâ˼Ï¡£ÐÂÊÖ¡£¡£²»ºÃÒâ˼¡£
Ïà¹ØÎÊ´ð£º
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Ä ......
tab1 ×Ö¶Î:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 ×Ö¶Î:goodsid,goodskind£¨ÉÌÆ·ÀàÐÍ£©
tab3 ×Ö¶Î:goodskind£¨ÉÌÆ·ÀàÐÍ£©,kindname
½á¹û£º
µÃµ½ÉÌÆ·ÀàÐÍÔÚÒ»¶Îʱ¼ä ......
ÏÖÔÚÓÐÒ»¸ö²¿Ãűídept£¨²¿ÃÅÃû³Æ£¬²¿Ãźš£¡££©ÓÐÒ»¸öÈËÔ±±íemp£¨ÐÕÃû£¬ÈËÔ±±àºÅ£¬Ö°Î»£¬Ð½×Ê£¬²¿ÃÅ£©
emp±íÖеÄÄÚÈÝÊÇÕâÑùµÄ£º
a 1 ¹¤³Ìʦ 3000 Èí¼þ²¿
b 2 ÆÕͨԱ¹¤ 2000 Ó²¼þ²¿
c 3 ¹¤³Ìʦ 4000 Ó²¼þ²¿
d ......
ÎÒÓÐÒ»¸ö×Ö¶ÎÊÇ varchar(1) ÀàÐÍ£¬¶þ½øÖƱíʾҲ¾ÍÊÇ8λµÄ ¡®0000 0000¡¯
±ÈÈçÕâ¸öʱºòÎÒÐèҪɸѡ³öÕâ¸ö×Ö¶ÎΪËùÓÐµÄ ¡®0000 0100¡¯µÄÐУ¬ÇëÎÊSQLÄÜʵÏÖÕâÑùµÄ¡°Î»¡±µÄɸѡÂð£¿
лл~~~
ÓÐλ²Ù×ݺ¯ÊýÂ𣿲»ÐоÍ× ......