最初の 2 文字がゼロの場合、どのように置き換えますか?
例:
1. 00001
2. 00123
3. 02451
次のようにする必要があります。
1. 11001
2. 11123
3. 02451
編集:言及するのを忘れていましたが、select句(ビュー内)でこれが必要ですありがとうございます。
最初の 2 文字がゼロの場合、どのように置き換えますか?
例:
1. 00001
2. 00123
3. 02451
次のようにする必要があります。
1. 11001
2. 11123
3. 02451
編集:言及するのを忘れていましたが、select句(ビュー内)でこれが必要ですありがとうございます。
update YourTable
set col1 = '11' + substring(col1, 3, len(col1)-2)
where col1 like '00%'
ビューでは、次のようにできます。
select case
when col1 like '00%' then stuff(col1, 1, 2, '11')
else col1
end
from YourTable;
declare @a varchar(10)
select @a='01123'
Select case when LEFT(@a,2)='00' then STUFF(@a,1,2,'11') else @a end
以下のような左の方法を使用することもできます
select case When left(Name,2) = '00' Then stuff(Name, 1, 2, '11')
else Name
end
from YourTable