sqlserveråçè¯æ³å¦ä¸ï¼æ¯å¦è¢«æå ¥ç表为B表ï¼å段为timeå段
insert into B (time) select replace(substring(CONVERT(VARCHAR(19),GETDATE(),120),12,8),':','')è¿é主è¦ç¨äºconvertå½æ°ï¼è¿æ¯sqlserverä¸ä¸ä¸ªè¿è¡æ°æ®ç±»å转åçå½æ°ã
ç¨æ³ç®ä»ï¼
ä¸ datetimeãsmalldatetime æ sql_variantä¸ç§æ°æ®ç±»å ä¸èµ·ä½¿ç¨æ¶ï¼
CONVERTåCAST æä¾ç¸ä¼¼çåè½ å³ï¼å°æç§æ°æ®ç±»åç表达å¼æ¾å¼è½¬æ¢ä¸ºå¦ä¸ç§æ°æ®ç±»åã
è¯æ³
ä½¿ç¨ CASTï¼
CAST ( expression AS data_type )
ä½¿ç¨ CONVERTï¼
CONVERT (data_type[(length)], expression [, style])
åæ°
expression
æ¯ä»»ä½ææç Microsoft SQL Server™ 表达å¼ãæå ³æ´å¤ä¿¡æ¯ï¼è¯·åè§è¡¨è¾¾å¼ã
data_type
ç®æ ç³»ç»ææä¾çæ°æ®ç±»åï¼å æ¬ bigint å Sql_variantãä¸è½ä½¿ç¨ç¨æ·å®ä¹çæ°æ®ç±»åãæå ³å¯ç¨çæ°æ®ç±»åçæ´å¤ä¿¡æ¯ï¼è¯·åè§æ°æ®ç±»åã
length
ncharãnvarcharãcharãvarcharãbinary æ varbinary æ°æ®ç±»åçå¯éåæ°ã
style
æ¥ææ ¼å¼æ ·å¼ï¼åä»¥å° datetime æ smalldatetime æ°æ®è½¬æ¢ä¸ºå符æ°æ®ï¼ncharãnvarcharãcharãvarcharãnchar æ nvarchar æ°æ®ç±»åï¼ï¼æè åç¬¦ä¸²æ ¼å¼æ ·å¼ï¼åä»¥å° floatãrealãmoney æ smallmoney æ°æ®è½¬æ¢ä¸ºå符æ°æ®ï¼ncharãnvarcharãcharãvarcharãnchar æ nvarchar æ°æ®ç±»åï¼ã