2013-06-13 10 views
5

Mam pole Integer i muszę je podzielić na Bits to the SQL(Firebird). Dla każdego bajtu pola Liczba całkowita powinno być nowe pole. Na przykład:Integer to Bit w SQL

Integer field: 7 = 00000111 

Bit 1 field1: 1 
Bit 2 field2: 1 
Bit 3 field3: 1 
Bit 4 Field4: 0 
Bit 5 Field5: 0 
Bit 6 Field6: 0 
Bit 7 Field7: 0 
Bit 8 Field8: 0 

ktoś wie jak to zrobić w Firebird?

Odpowiedz

3

Użyj BIN_AND funkcję:

SELECT 
    bin_and(field, 1) as bit1, 
    bin_and(field, 2) as bit2, 
    bin_and(field, 4) as bit3, 
    bin_and(field, 8) as bit4, 
    ... 
FROM T 
+0

Dzięki @ain Dokładnie to, czego szukałem. –