question

BrentonK avatar image
BrentonK asked

Re-running multiple updates

Hi, I have a number of Updates I'm running sequentially. When I add new data to the dataset I'd like the whole code to run in 1 go rather than each Update individually.

Here's a snippet of my code. I'm new to SQL, and am sure this is not the optimal way of writing it...!! (The reason for the final line in each Update is I don't want to overrwrite a previously categorised FullDesc).

update bankstatements.transactions
set sandpit2 = 'Health'
where FullDesc like '%Mcare%'
and sandpit2 is null;


update bankstatements.transactions
set sandpit2 = 'Centrelink'
where FullDesc like '%Ctrlink%'
and sandpit2 is null;


update bankstatements.transactions
set sandpit2 = 'Rental Bond'
where FullDesc like '%residential tena%'
and sandpit2 is null;


update bankstatements.transactions
set sandpit2 = 'Auto'
where FullDesc like '%7-eleven%'
and sandpit2 is null;

update bankstatements.transactions
set sandpit2 = 'ATM'
where fulldesc like '%cash out%'
and sandpit2 is null;


update bankstatements.transactions
set sandpit2 = 'Auto'
where fulldesc like '%coles express%'
and sandpit2 is null;


update bankstatements.transactions
set sandpit2 = 'Groceries'
where fulldesc like '%Coles%'
and sandpit2 is null;


code
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jon Crawford avatar image
Jon Crawford answered

Try using a CASE statement instead

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.