2014-09-29 2 views
-2

이 쿼리를 만들려고 시도했지만 구문이 잘못되어 왜 그 이유가 확실하지 않습니다. 슬래시를 이스케이프 처리해야합니까?SQL - 잘못된 구문 - 슬래시가 포함 된 문자열을 변수로 사용

with x as (
    select 
     job_id, 
     avg_runtime, 
     id, 
     row_number() over (partition by ja.job_id order by ja.id desc) rn 
    from 
     job_activity as ja 
      join 
     job as j 
      on ja.job_id = j.id 
    where 
     j.name in ('/THE/Name/goes/here') 
     and 
     ja.avg_runtime <> 0 and 
     ja.avg_runtime is not null   
) select 
    job_id, 
    avg_runtime, 
    id 
from 
    x 
where 
    rn = 1; 
+0

''/ THE/Name/goes/here '' – Mihai

+0

그것은 Invaild 열 이름입니다. 이유가 확실하지 않은가요? 그 특정 줄 ON/THE/Name/goes/here ' – user3590149

+0

실제 문자열을 표시하십시오./공백 앞에 숫자가 있습니까? 또한 SQL Server를 추측합니까? – Mihai

답변

0

쿼리는있는 그대로 실행해야합니다. 자리 표시 자로 깎은 끈을 사용하고 있습니까? 그렇다면 다음을 시도해보십시오.

Declare @JobToFind VarChar(30) 

Set @jobtofind = 'Search string (job name)'--modify the value in the quotes. 

with x as (
    select 
     job_id, 
     avg_runtime, 
     j.ID, 
     row_number() over (partition by ja.job_id order by ja.id desc) rn 
    from 
     job_activity as ja 
      join 
     job as j 
      on ja.job_id = j.id 
    where 
     j.name [email protected] 
     and 
     ja.avg_runtime <> 0 and 
     ja.avg_runtime is not null   
) select 
    job_id, 
    avg_runtime, 
    id 
from 
    x 
where 
    rn = 1; 
관련 문제