>>>>Hi,
>>>>
>>>>I have the following SQL Select (simplified):
>>>>
>>>>
>>>>cSqlselect = "SELECT " + cGroupField + " AS GROUP_ID " .... GROUP BY " + cGroupField
>>>>
>>>>
>>>>I want all records where the cGroupField is empty or NULL to be grouped into one record. But I get one row for all empty values and one row for all NULL values.
>>>>
>>>>How do you suggest I change the above SQL Select?
>>>>
>>>>TIA
>>>
>>>Dmitry
>>>
>>>Assuming you're working with MSSQL Server, use the ISNULL() function to transform NULL values into empty ones. For instance, for a column X with data type integer (null):
>>>
>>>
>>>SELECT ISNULL(x, 0) FROM table_x GROUP BY ISNULL(x, 0);
>>>
>>
>>Hi Antonio,
>>I forgot that SQL Server has ISNULL() function (equivalent of NVL of VFP). This should work.
>>Thank you very much!
>
>Great!
>
>For the record, NVL() is in use in ORACLE, too.
Sorry to trouble you again. Why do you think if I replace 0 (in your code above) with space(len()), my SQL selects NULLs?
Here is how my code looks like:
SELECT ISNULL(x, space(len(x)) FROM table_x GROUP BY ISNULL(x, space(len(x));
Do you see what I am missing?
UPDATE. I replaced SPACE(...) with '' (empty string) and all works fine.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham