用SUBSTRING...
<pre class="c" name="code">SELECT SUBSTRING([BARCODE],1,20) AS [條碼],SUBSTRING([PROD],1,20) AS [品號].....
ander6879提到:
declare @barcode varchar(20),@prod varchar(20)
set @barcode='8888888888'
set @prod='1234567890'SELECT SUBSTRING(@barcode,1,20)+REPLICATE('0',20-LEN(@barcode))+SUBSTRING(@prod,1,20)+REPLICATE('0',20-LEN(@prod))
iT邦幫忙MVPwiselou提到:
用SUBSTRING...
1、用SUBSTRING...,會跳一格空白值,因為要SELECT 多個格式。
2、TO allenwh:
set @barcode='8888888888'set @prod='1234567890'如何更改為欄位值,因db非一筆,是一整個欄位值
SELECT SUBSTRING(barcode,1,20)+REPLICATE('0',20-LEN(barcode))+SUBSTRING(prod,1,20)+REPLICATE('0',20-LEN(prod)) from table_name
參考wiselou前輩的語法,將原字串後面補上'X'
<pre class="c" name="code">
declare @barcode varchar(20),@prod varchar(20)
set @barcode='8888888888'
set @prod='1234567890'
SELECT SUBSTRING(@barcode,1,20)+REPLICATE('X',20-LEN(@barcode))+SUBSTRING(@prod,1,20)+REPLICATE('X',20-LEN(@prod))