Reputation: 1010
I've been working on learning SQL starting with basically no knowledge. I've only been at this for about a week.
I'm working with a piece of simulation software. I've been given a task to run many replications of a simulation that will generate random events of either something happens or nothing happens. The sim will create a table of the events and a column for replication numbers. If the event happened then it will get an event number, if it didn't, it will skip that rep and go to the next. I need a query to take the replications that have no event and replace the null
entry with a zero
.
As an added bonus, I might need to generate the number for the replication where there is a null
.
The last bit of code I tried looked like this:
SELECT IsNull(table1.column1, 0)
FROM table1
Upvotes: 0
Views: 75
Reputation: 3606
SELECT COALESCE(table1.column1,0)
FROM table1
Should do the trick. COALESCE returns the first non-null value it finds, so this should work.
Upvotes: 2