| | |
search
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
I have asp.net C# web application I want to search jobvacancy details using jobrole.
if user did not select any value I want to select all the details including null values.
this Jobvacancy table has JobRole feild and it allow to insert null values,
this is my stored procedure
when I use @JobRole value as '%' then if JobRole feild has null value it did not select.
but I want to select all the values including null values. how can I do this?
if user did not select any value I want to select all the details including null values.
this Jobvacancy table has JobRole feild and it allow to insert null values,
this is my stored procedure
MS SQL Syntax (Toggle Plain Text)
CREATE PROCEDURE JobVacancy ( @JobRole varchar (50) ) AS SELECT NoOfVacancies,JobRole FROM JobVacancy WHERE JobRole LIKE @JobRole + '%'
when I use @JobRole value as '%' then if JobRole feild has null value it did not select.
but I want to select all the values including null values. how can I do this?
Thanks for your help using your ideas finally I manage to write a correct query,
:evil:
MS SQL Syntax (Toggle Plain Text)
CREATE PROCEDURE JobVacancy ( @JobRole varchar (50) ) AS IF @JobRole <> '%' begin SELECT NoOfVacancies,JobRole FROM JobVacancy WHERE JobRole LIKE @JobRole+ '%' end else begin SELECT NoOfVacancies,JobRole FROM JobVacancy WHERE (JobRole LIKE @JobRole+ '%' OR JobRole IS NULL) end
no problem, but with your solution i don't understand why you use an if..else statement here
im sure you'd get the same result by just saying
select NoOfVacancies, JobRole
from JobVacancy
where JobRole like @JobRole + '%'
or JobRole is null
if @JobRole is '%' your statement would say '..where JobRole like '%%' which is the same as saying where JobRole like '%'; both solutions would work but I think you may be overcomplicating slightly.
on the right track though
•
•
•
•
Originally Posted by aish
MS SQL Syntax (Toggle Plain Text)
IF @JobRole <> '%' begin SELECT NoOfVacancies,JobRole FROM JobVacancy WHERE JobRole LIKE @JobRole+ '%' end else begin SELECT NoOfVacancies,JobRole FROM JobVacancy WHERE (JobRole LIKE @JobRole+ '%' OR JobRole IS NULL) end
select NoOfVacancies, JobRole
from JobVacancy
where JobRole like @JobRole + '%'
or JobRole is null
if @JobRole is '%' your statement would say '..where JobRole like '%%' which is the same as saying where JobRole like '%'; both solutions would work but I think you may be overcomplicating slightly.
on the right track though
![]() |
Similar Threads
- Getting Your Site Submitted to Search Engines (Search Engine Optimization)
- search-town keeps coming up as my new home page (Web Browsers)
- Search for Information From the Address Bar in Internet Explorer (Windows tips 'n' tweaks)
- Quick Search Tips (Windows tips 'n' tweaks)
- Turn Off Display and Select an Animated Character in Search Companion in Windows XP (Windows tips 'n' tweaks)
- Using Search Engine Friendly PHP URLs (PHP)
- help please cannot use search button on ie6 (Web Browsers)
Other Threads in the MS SQL Forum
- Previous Thread: user creation using msde
- Next Thread: database reminders
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last autogrowth business connectingtodatabaseinuse count cursor data database dateadd datepart day" dbsize deadlock delete_trigger getdate highperformancecomputing hpc hpcserver2008 ibm iis loop maximum microsoft ms mssql multiple multithreading news number permission query reporting result server services sets source sql sqlserver sqlserver2005 supercomputing tables uniqueid update view weekday





