SQLTeam.com | Weblogs | Forums

Write and run a sql query, with no starter code to answer this question: What Step are Job Codes 0110-0400?

I am doing 'SQL for data science' course on Coursera, and I came across a question in solving the practice quiz.It has a tabled shown in the picture.


The question is "Write and run a sql query, with no starter code to answer this question: What Step are Job Codes 0110-0400?"
For the earlier questions, I had to convert the string data into numerical to satisfy the given conditions. But it is not working in this situation.

My attempt for this question was :
select * from salary_range_by_job_classification
WHERE Job_code between CAST(0110) AS INT AND CAST(0400) AS INT

Please correct me if I am wrong.

-- this is what missed
--cast (Job_Code as INT )

SELECT 
   step 
FROM    
  salary_range_by_job_classification
WHERE 
  cast (Job_Code  as INT ) between   CAST(0110) AS INT AND CAST(0400) AS INT
1 Like

I'd be careful casting Job_code as an int. It is clearly stored as a character string. There may be alpha characters in there that would cause it to error out. Try this

declare @t table (job_code char(4))
insert into @t 
values
('0099'),
('0100'),
('0110'),
('0310'),
('0401'),
('0400'),
('1')

select * from @t where job_code between '0110' and '0400'

Oh thank you for the solution ! I'll definitely try it .