How to avoid the null values…
Table1
ID Value1 Value2
001 Rajan null
001 Vijayan null
001 null ravi
001 null sudeep
002 kumar null
002 null venkat
.....
I don’t want to display null values.
Expected Output
ID Value1 Value2
001 Rajan ravi
001 Vijayan sudeep
002 kumar venkat
.....
How to make a query for the above condition
Need Query Help
Unless you explain in more detail how those values from
Value1andValue2columns belong together, and only if that “matching” is really deterministic, then you could do something like this:That would give you one row for each value of
ID, with the non-NULL value forValue1and the non-null value forValue2.But as your question stands right now, this approach doesn’t work, since you have multiple entries for the same ID – and no explanation as to how to match the two separate values together….
So as it stands right now, I would say there is no deterministic and proper solution for your question. You need to provide more information so we can find a solution for you.
Update: if you would update to SQL Server 2005 or newer, you could do something like two nested CTE’s – but in that case, too, you would have to define some rule / ordering as to how the two variants with
ID = 001are joined together…..Something like:
would give you a reproducible output of:
This is under the assumption that given two entries with the SAME ID, you want to sort (
ORDER BY) the actual values (e.g.RajanbeforeVijayanandRavibeforesudeep–> there you’d joinRajanandRavitogether, as well asVijayanandsudeep).But again: this is in SQL Server 2005 and newer only – no equivalent in SQL Server 2000, unforutnately…..