SORU
2 Aralık 2008, Salı


Nasıl Sql server bir dize null veya boş ise kontrol edebilirim

Verileri kontrol etmek istiyorum ama eğer null veya boş ise bunu görmezden. Şu anda sorgu şunlar var:

Select              
Coalesce(listing.OfferText, company.OfferText, '') As Offer_Text,         
from tbl_directorylisting listing  
 Inner Join tbl_companymaster company            
  On listing.company_id= company.company_id

Ama şirket almak istiyorum.Liste halinde OfferText.Offertext eğer null ise boş bir dize gibi.

En iyi performans gösteren çözüm nedir?

CEVAP
13 Temmuz 2010, Salı


Bu bence

SELECT 
  ISNULL(NULLIF(listing.Offer_Text, ''), company.Offer_Text) AS Offer_Text
FROM ...

en zarif çözümdür.

Ve bunu yıkmak sahte kod içinde bir bit için:

// a) NULLIF:
if (listing.Offer_Text == '')
  temp := null;
else
  temp := listing.Offer_Text; // may now be null or non-null, but not ''
// b) ISNULL:
if (temp is null)
  result := true;
else
  result := false;

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Photoshop Pro Help

    Photoshop Pr

    1 Ocak 2007
  • bored before i even began

    bored before

    30 Mart 2009
  • warningthepeople

    warningthepe

    21 EYLÜL 2011