SELECT CONCAT('PO',CONVERT(CHAR(6),GETDATE(),12) + RIGHT('0000'+CAST(COUNT(*)+1 AS VARCHAR(5)),5)) AS PSID FROM TB_MFPOS WHERE OS_ID='PO' 以上在sql2008运行又可以
金色年华(提问者)运行的时候出现了这个错误:[SQL]SELECT CONCAT(\'PO\',date_format(CURRENT_DATE(),\'%y%m%d\')) + RIGHT(\'0000\'+CAST(COUNT(*)+1 AS VARCHAR(5)),5)) AS PSID FROM TB_MFPOS WHERE OS_ID=\'PO\'
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'VARCHAR(5)),5)) AS PSID FROM TB_MFPOS WHERE OS_ID=\'PO\'\' at line 1