Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
micnie_2020
Posting Yak Master
232 Posts |
Posted - 2012-03-21 : 23:06:55
|
Dear ALl,I have a table contain:Type Company RateSoftware ABC 5Software Null 3Hardware Null 2if Type=Software1. Company=ABD (Rate: 3) 2. Company=ABC (Rate: 5)3. Company=Null (Rate: 3)I looking for single sql not Stored procedure.I will past in the 2 parameter; Type & Company. IIf not exist in the MS SQL 2008. I can't perform the work.Please advise.Thank you.Regards,MichealeHow can i do that? |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-03-21 : 23:17:01
|
you can use CASE WHEN KH[spoiler]Time is always against us[/spoiler] |
|
|
micnie_2020
Posting Yak Master
232 Posts |
Posted - 2012-03-21 : 23:26:36
|
Thank you. I found the solution.Here it go...IF exists (SELECT Rate FROM tblTypeSetup WHERE (Company = 'ABD'))SELECT Rate FROM TypeSetup WHERE [Type]='Software' and (Company = 'ABD') ELSESELECT Rate FROM TypeSetup WHERE [Description]='Software' and Company is null |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-03-21 : 23:31:52
|
[code]SELECT top 1 Rate FROM TypeSetupWHERE [Type] = 'Software' and ( Company is null or Company = 'ABD' )ORDER BY Company DESC[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|