This counts the non-NULL/blank values. Note that Column1 was assumed
to be some number data type (int, decimal, etc) and so there is no
code to handle blanks. Any count of zero indicates a column with only
NULL or blank.
SELECT COUNT(*) as Total,
COUNT(Column1) as Column1,
COUNT(CASE WHEN Column2 = ' '
THEN NULL
ELSE Column2
END) as Column2,
COUNT(CASE WHEN Column3 = ' '
THEN NULL
ELSE Column3
END) as Column3
FROM SomeTable
Roy Harvey
Beacon Falls, CT
On Thu, 11 Oct 2007 09:51:23 -0400, "Jamie"
[quoted text, click to view] <Jlawson01@OMITTHIS.lear.com> wrote:
>I need someway of locating all the columns in a table where the entire
>column is either NULL or ''.
>
>Does anyone know an easy way to do this against a table with about 30
>columns? Or any suggestions???
>
>Column 1 Column 2 Column 3
>-------- -------- --------
>1 NNN
>2 NNYIUI
>
>In the above example it would let me know that Column 2 doesn't have data
>and or if it could let me know about column 1 and 3 I can figure out Column
>2 is the one I'm looking for.
Getting error
Incorrect syntax near the keyword 'FROM'.
END) as Receipt_ASN,
FROM labels
Last two lines of code.
[quoted text, click to view] "Roy Harvey (SQL Server MVP)" <roy_harvey@snet.net> wrote in message
news:h4dsg3p35hlts63gmd65b5ujg0ds7pa04i@4ax.com...
> This counts the non-NULL/blank values. Note that Column1 was assumed
> to be some number data type (int, decimal, etc) and so there is no
> code to handle blanks. Any count of zero indicates a column with only
> NULL or blank.
>
> SELECT COUNT(*) as Total,
> COUNT(Column1) as Column1,
> COUNT(CASE WHEN Column2 = ' '
> THEN NULL
> ELSE Column2
> END) as Column2,
> COUNT(CASE WHEN Column3 = ' '
> THEN NULL
> ELSE Column3
> END) as Column3
> FROM SomeTable
>
> Roy Harvey
> Beacon Falls, CT
>
> On Thu, 11 Oct 2007 09:51:23 -0400, "Jamie"
> <Jlawson01@OMITTHIS.lear.com> wrote:
>
>>I need someway of locating all the columns in a table where the entire
>>column is either NULL or ''.
>>
>>Does anyone know an easy way to do this against a table with about 30
>>columns? Or any suggestions???
>>
>>Column 1 Column 2 Column 3
>>-------- -------- --------
>>1 NNN
>>2 NNYIUI
>>
>>In the above example it would let me know that Column 2 doesn't have data
>>and or if it could let me know about column 1 and 3 I can figure out
>>Column
>>2 is the one I'm looking for.
>>
By the way thank you for this it worked great.
[quoted text, click to view] "Roy Harvey (SQL Server MVP)" <roy_harvey@snet.net> wrote in message
news:h4dsg3p35hlts63gmd65b5ujg0ds7pa04i@4ax.com...
> This counts the non-NULL/blank values. Note that Column1 was assumed
> to be some number data type (int, decimal, etc) and so there is no
> code to handle blanks. Any count of zero indicates a column with only
> NULL or blank.
>
> SELECT COUNT(*) as Total,
> COUNT(Column1) as Column1,
> COUNT(CASE WHEN Column2 = ' '
> THEN NULL
> ELSE Column2
> END) as Column2,
> COUNT(CASE WHEN Column3 = ' '
> THEN NULL
> ELSE Column3
> END) as Column3
> FROM SomeTable
>
> Roy Harvey
> Beacon Falls, CT
>
> On Thu, 11 Oct 2007 09:51:23 -0400, "Jamie"
> <Jlawson01@OMITTHIS.lear.com> wrote:
>
>>I need someway of locating all the columns in a table where the entire
>>column is either NULL or ''.
>>
>>Does anyone know an easy way to do this against a table with about 30
>>columns? Or any suggestions???
>>
>>Column 1 Column 2 Column 3
>>-------- -------- --------
>>1 NNN
>>2 NNYIUI
>>
>>In the above example it would let me know that Column 2 doesn't have data
>>and or if it could let me know about column 1 and 3 I can figure out
>>Column
>>2 is the one I'm looking for.
>>