我在SQL Server 2000中編寫了一個存儲過程。我想要一個輸出表的序列號。 所以,當我運行這個存儲過程中我得到這個錯誤:sql查詢序列號
An explicit value for the identity column in table '#tmpSearchResults1' can only be specified when a column list is used and IDENTITY_INSERT is ON.
我與set IDENTITY_INSERT #tmpSearchResults1 on
Create Procedure dbo.usp_mobile_All_KeyWord(@searchkey varchar(30))
AS
CREATE TABLE #tmpSearchResults
(
property_id varchar(255),
property_number varchar(255),
auction_date_reason varchar(255)
)
INSERT INTO #tmpSearchResults
SELECT
p.property_id, p.property_number, p.auction_date_reason
FROM
Pr p
INNER JOIN
Au a ON p.auction_id = a.auction_id
INNER JOIN
PrAdd pa ON p.property_id = pa.property_id
INNER JOIN state AS s ON s.state_id=pa.state
where
(
(p.archive = 'N'
AND
a.show_on_site = 'Y'
AND
(
(
((p.auction_date >= CONVERT(datetime, CONVERT(varchar, GETDATE(), 103), 103) and (p.auction_date_reason is null or p.auction_date_reason = ''))
or
(p.auction_date <= CONVERT(datetime, CONVERT(varchar, GETDATE(), 103), 103) and (p.auction_date_reason = 'Accepting Offers')))
and
pa.property_address_type_id = 1)))
and
([email protected] or s.state_name like '%'+''+ @searchkey +''+'%' or city like '%'+''+ @searchkey +''+'%' or pa.address1 like '%'+''+ @searchkey +''+'%'
or pa.address2 like '%'+''+ @searchkey +''+'%')
)
)
CREATE TABLE #tmpSearchResults1
(
i1 int identity,
property_id varchar(255),
property_number varchar(255),
auction_date_reason varchar(255)
)
insert into #tmpSearchResults1
select
property_id ,
property_number,
auction_date_reason
from #tmpSearchResults
order by
case when charindex(@searchkey,state) >0 then 1000 else 0 end desc,
case when charindex(@searchkey,statename) >0 then 1000 else 0 end desc,
case when charindex(@searchkey,city) >0 then 1000 else 0 end desc,
case when charindex(@searchkey,address2) >0 then 1000 else 0 end desc,
case when charindex(@searchkey,address1) >0 then 1000 else 0 end desc,
case when charindex(@searchkey,short_description) >0 then 1000 else 0 end desc
select * from #tmpSearchResults1
試圖PLZ你幫我
謝謝,它的工作 – Sree
@Sree - 很樂意幫忙。密切關注錯誤代碼,SQL Server中的很多時間都非常具體和有用。 – JNK
@JNK:提供一個實際**讀**他們! :..... –