•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 402,420 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,041 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 1961 | Replies: 4
![]() |
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
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?
•
•
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation:
Rep Power: 3
Solved Threads: 31
Thanks for your help using your ideas finally I manage to write a correct query,
:evil:
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
•
•
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation:
Rep Power: 3
Solved Threads: 31
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
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
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adsense advertising ajax asp blogging bomb book business coding copyright database developer development earth engine environment failure forum google hacker internet legal malware marketing mcafee microsoft monetization msdn news operating phishing privacy publishing revenue search security silverlight software space spyware sql support survey system technical universe web webmaster wiki yahoo
- 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


Linear Mode