使用SP将值插入Temp表SQL Server 2005 [英] Inserting values into Temp table SQL Server 2005 using SP
本文介绍了使用SP将值插入Temp表SQL Server 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好全部,
何时我跑了这个查询我得到结果 2 和 < span class =code-digit> 5 和两个单独的行......我是否有值 2 , 5 , my 列 my table 。 ..
[代码] DECLARE @ Test VARCHAR ( 1000 ), @ RecSet VARCHAR ( 500 ), @ ID V ARCHAR ( 10 ), @ Value VARCHAR ( 60 )
DECLARE @ StartingPos INT , @ RecPos INT
DECLARE @ TEMPEXPECTATION TABLE (COMPLEXIONID INT )
SET @ StartingPos = 1
SET @ Test =(选择 cmp.complexion1 来自 customerexpectation cmp 其中 cmp.customerid = ' be65cb50-cc1d-47a5-a3a2-657fae4e6519')
WHILE @ StartingPos< = LEN( @ Test )
BEGIN
SELECT @ RecPos = CHARINDEX(' ,', @ Test , @ StartingPos )
SELECT @ RecSet = SUBSTRING( @ Test , @ StartingPos ,@ RecPos- @ StartingPos)
PRINT @RecSet
- INSERT INTO @TEMPEXPECTATION(@ID)
SELECT @ StartingPos = @ RecP os + 1
END
[/ CODE]
现在我需要 to insert 此值 2 和 5 暂时< span class =code-keyword> table 使用上述查询 制作 as 存储过程 ...请找到解决方案......
解决方案
创建 表 #tempdata(ID INT IDENTITY ( 1 , 1 ),FirstValue INT ,LastValue INT )
INSERT INTO #tempdata (FirstValue,LastValue) VALUES ( @ RecPos , @ RecSet )
嗨...在运行此查询时我得到的值为2,5,然后通过使用一些拆分机制我分裂值分别为2和5现在我需要将这两个值插入临时表中,其中列为complexionid ...我希望它很清楚arindamurdra ...
选择 cmp.complexion1 来自 customerexpectation cmp 其中 cmp.customerid = ' be65cb50-cc1d-47a5-a3a2-657fae4e6519'
Hi all,
When i ran this query i get result as 2 and 5 and two individual rows....wher i have the values 2,5, in my column of my table...
[CODE]DECLARE @Test VARCHAR(1000), @RecSet VARCHAR(500), @ID VARCHAR(10), @Value VARCHAR(60)
DECLARE @StartingPos INT,@RecPos INT
DECLARE @TEMPEXPECTATION TABLE(COMPLEXIONID INT)
SET @StartingPos= 1
SET @Test =(select cmp.complexion1 from customerexpectation cmp where cmp.customerid='be65cb50-cc1d-47a5-a3a2-657fae4e6519')
WHILE @StartingPos<=LEN(@Test)
BEGIN
SELECT @RecPos = CHARINDEX(',',@Test,@StartingPos)
SELECT @RecSet=SUBSTRING(@Test,@StartingPos,@RecPos-@StartingPos)
PRINT @RecSet
--INSERT INTO @TEMPEXPECTATION(@ID)
SELECT @StartingPos=@RecPos+1
END
[/CODE]
Now i need to insert this values 2 and 5 in a temporary table using the above query to made as Stored Procedure...Pls find the solution...
解决方案
Create TABLE #tempdata (ID INT IDENTITY(1,1), FirstValue INT, LastValue INT) INSERT INTO #tempdata (FirstValue,LastValue) VALUES (@RecPos,@RecSet)
Hi..while run this query i am getting the values as 2,5, then by using some splitting mechanism i am splitting the values as 2 and 5 respectively now i need to insert these two values in a temp table with column as complexionid...i hope it''s clear arindamurdra...
select cmp.complexion1 from customerexpectation cmp where cmp.customerid='be65cb50-cc1d-47a5-a3a2-657fae4e6519'
这篇关于使用SP将值插入Temp表SQL Server 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文