简体   繁体   中英

return string value from SQL Server tables where column type is integer

In my mssql tables i have a clomun that data type is integer. and when i was try thats you know the return value is int.

select h.hekimlik_kod, h.hekim_adi, h.hekim_soyadi, h.il_kod, h.ilce_kod, h.islem_tarihi, h.durum
h.asm, il.aciklama as il_adi, ilce.aciklama as ilce_adi from hekim as h
left join il_ilce as il on il.ust_kod = 0 and il.kod = h.il_kod 
left join il_ilce as ilce on ilce.ust_kod = h.il_kod and ilce.kod = h.ilce_kod

int this sql statement "h.durum"' data type is integer. but i want to make thats. when h.durum is 0 return string is Yönetici when h.durum 1 string is Normal Kullanıcı

how can i do in sql? thank you for patience

Not sure if I understood the question, but try replacing h.durum on your SELECT with the following:

CASE WHEN h.durum = 0 THEN 'Yönetici'
     WHEN h.durum = 1 THEN 'Normal Kullanıcı'
     ELSE '???' END AS some_column_alias

Try this:

select
  CASE
    WHEN h.durum = 0 THEN N'Yönetici'
    WHEN h.durum = 1 THEN N'Normal Kullanıcı'
  END CASE ColumnName,
  h.hekimlik_kod, h.hekim_adi, h.hekim_soyadi, h.il_kod, h.ilce_kod, h.islem_tarihi, h.durum
  h.asm, il.aciklama as il_adi, ilce.aciklama as ilce_adi
FROM hekim as h
  left join il_ilce as il on il.ust_kod = 0 and il.kod = h.il_kod 
  left join il_ilce as ilce on ilce.ust_kod = h.il_kod and ilce.kod = h.ilce_kod
;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM