2013-07-16 57 views
-1

enter image description here你好,獲取從列唯一編號使用SQL

我想通過使用從列ProecssInstanceName一個SQL查詢來獲取的唯一編號。快照如下所示。

現在我使用此查詢來獲取以下結果。查詢是

select c.StreamName AS Category,ProcessInstanceAppianID as jobId,a.ProcessInstanceName,a.ProcessInstanceTargetDate AS TargetDate,a.ProcessInstanceDescription as TaskDescription,b.Name as department 
from InternalUseOnly..ProcessInstance a 
join InternalUseOnly..Departments b on b.KeyDepartment=a.KeyDepartmentEntered AND b.updoperation <2 
join InternalUseOnly..ProcessStream c on c.KeyProcessStream=a.KeyProcessStream and c.updoperation <2 
where ProcessInstanceCompleted is null 
and a.KeyProcessStream in 
(330) and a.updoperation <2 

在此先感謝。

+0

我想你想使用'DISTINCT',但我不確定我是否有問題。 – asafrob

+0

基於結果集後所需的輸出圖片中所顯示 – peterm

+0

嘗試......力測試... SELECT SUBSTRING(ProecssInstanceName,PATINDEX( '%[0-9]%',ProecssInstanceName,LEN(ProecssInstanceName))) AS號FROM表名; –

回答

0

你想要這個嗎?

select c.StreamName AS Category,ProcessInstanceAppianID as jobId,a.ProcessInstanceName,a.ProcessInstanceTargetDate AS TargetDate,a.ProcessInstanceDescription as TaskDescription,b.Name as department, 
SUBSTRING(ProcessInstanceName,NULLIF(PATINDEX('%[0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',ProcessInstanceName),0),7) as code 
from InternalUseOnly..ProcessInstance a 
join InternalUseOnly..Departments b on b.KeyDepartment=a.KeyDepartmentEntered AND b.updoperation <2 
join InternalUseOnly..ProcessStream c on c.KeyProcessStream=a.KeyProcessStream and c.updoperation <2 
where ProcessInstanceCompleted is null 
and a.KeyProcessStream in 
(330) and a.updoperation <2 

編輯: 我做了這個:

SUBSTRING(ProcessInstanceName, PatIndex('%[0-9]%', ProcessInstanceName), (LEN(ProcessInstanceName) - (PatIndex('%[0-9]%', ProcessInstanceName) - 1) - (PatIndex('%[0-9]%', REVERSE(ProcessInstanceName)) - 1)) + 1) 

但我認爲這是瘋狂的,更好的是C#或者你用什麼來解析號碼。

+0

我在這些數字中計數7位數 –

+0

@Damien_The_Unbeliever謝謝,我的壞眼睛 – slavoo

+0

它顯示[不正確的語法附近'SUBSTRING'。] – Anoop

0

我建議使用string functionsREPLACE「Webwatcher再過濾網址的」空白並使用LEFTPATINDEX合力得到ID和演員陣容的數量。