Sql 字符串轉(zhuǎn)換為行
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))
declare @str varchar(20),@strSql varchar(8000)
set @str = 'a,bc,d,abce,ddz,78787' -- 此處的字符串可以隨心所欲的更改
if object_id('tempdb.dbo.#temp1') is null
create table #temp1(item varchar(20))
else
truncate table #temp1
SELECT @strSql='insert into #temp1 values('''+REPLACE(@str,',',''') insert into #temp1 values(''')+''')'
print @strSql
exec (@strSql)
select * from #temp1

浙公網(wǎng)安備 33010602011771號(hào)