use*_*503 -1 sql sql-server stored-procedures
我有如下要求:
SELECT code from Products
Run Code Online (Sandbox Code Playgroud)
样品:
If code is : 1234 => 00001234
12345 => 00012345
..... => xxxxxxxx
Run Code Online (Sandbox Code Playgroud)
我想在SQL Server 2012中使用存储过程来执行此操作.
如果CODE字段是字符串,这将起作用
SELECT RIGHT('00000000'+ISNULL(CODE,''),8) from Products
Run Code Online (Sandbox Code Playgroud)
如果CODE是整数那么
SELECT RIGHT('00000000'+CAST(CODE AS VARCHAR(8)),8) from Products
Run Code Online (Sandbox Code Playgroud)