Skip to main content

Can SQLCreator/SQLExecutor create columns and alter values. I've completed all the left join I require and now wanting to create a new column with calculated values.

Duplicate an existing column with new name / Select existingTable.existingColumn as newColumn

Can I use if-then statements / If existingTable.existingValue = 'DI' then newColumn = '1234'

Yes, assuming you have the correct permissions of course. It's more common to use the SQLExecutor for it, but keep in mind it will be triggered for every input feature. It'll then send the SQL query to the database.


@hlouie As @redgeographics mentions, you can use pretty well any SQL statement in SQLCreator or SQLExecutor. These transformers do not have to return any data, If you right click on a table in the Database tables list, you get examples of SQL scripts.

The Run... button lets you test your scripts - use with caution! A short tutorial on the Knowledge Centre and perhaps this section


@hlouie As @redgeographics mentions, you can use pretty well any SQL statement in SQLCreator or SQLExecutor. These transformers do not have to return any data, If you right click on a table in the Database tables list, you get examples of SQL scripts.

The Run... button lets you test your scripts - use with caution! A short tutorial on the Knowledge Centre and perhaps this section

With the SQL statement below

 

I can add a new column under select with

COMP.PIPETYPE AS PAC_NO,

 

But how do I change the values in this new column?

Can I use if-then statements / If PAC_NO = 'DI' then PAC_NO = '1234'

 

/*

SewerServiceLine

*/

SELECT COMP.*,

VAR.*,

UNITTYPE.PDESCRIPT] AS UNITTYPE_RESOLVED,

 

ADDRKEY.KCACITY],

ADDRKEY.KCAPOSTDIR],

ADDRKEY.KCAPROVINCE],

ADDRKEY.KCASTNAME],

ADDRKEY.KCASTNO],

ADDRKEY.KCASUFFIX],

STKEY.KDESCRIPT] AS SEGKEY_RESOLVED,

 

AREA.ADESCRIPT] AS AREA_RESOLVED,

SUBAREA.ADESCRIPT] AS SUBAREA_RESOLVED,

DISTRICT.RDESCRIPT] AS DISTRICT_RESOLVED,

LOC.>DESCRIPT] AS LOC_RESOLVED,

 

PIPETYPE.EDESCRIPT] AS PIPETYPE_RESOLVED,

SURF.>DESCRIPT] AS SURF_RESOLVED,

SIC.pDESCRIPT] AS SIC_RESOLVED,

SRVTYPE.VDESCRIPT] AS SRVTYPE_RESOLVED,

 

MFGKEY.MCODE] AS MFGKEY_RESOLVED,

 

SERVSTAT.EDESCRIPT] AS SEVRSTAT_RESOLVED,

OWN.>DESCRIPT] AS OWN_RESOLVED

 

FROM ASSETMANAGEMENT_SEWER.NCOMPSSL] AS COMP

LEFT JOIN BURNABY. VARSSL] AS VAR ON COMP. COMPKEY] = VAR.YCOMPKEY]

LEFT JOIN ASSETMANAGEMENT_SEWER.NSEWERSERVICETYPE] AS UNITTYPE ON COMP. UNITTYPE] = UNITTYPE.UCODE]

 

LEFT JOIN PROPERTY. ADDRESS] AS ADDRKEY ON COMP.YADDRKEY] = ADDRKEY.=ADDRKEY]

LEFT JOIN ASSETMANAGEMENT_STREET.NCOMPSEG] AS COMPSEG ON COMP.GSEGKEY] = COMPSEG.=COMPKEY]

LEFT JOIN ASSETMANAGEMENT_STREET.NSTREET] AS STKEY ON COMPSEG.NSTKEY] = STKEY.]STKEY]

 

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERAREA] AS AREA ON COMP.EAREA] = AREA.ECODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERSUBAREA] AS SUBAREA ON COMP.ESUBAREA] = SUBAREA. CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERDISTRICT] AS DISTRICT ON COMP.CDISTRICT] = DISTRICT.=CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERLOCATION] AS LOC ON COMP.OLOC] = LOC.LCODE]

 

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERPIPETYPE] AS PIPETYPE ON COMP.YPIPETYPE] = PIPETYPE. CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERSIC] AS SIC ON COMP.SSIC] = SIC.[code]

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERSERVICETYPE] AS SRVTYPE ON COMP.YSRVTYPE] = SRVTYPE.]CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERSURFACECOVER] AS SURF ON COMP.USURF] = SURF.UCODE]

 

LEFT JOIN RESOURCES.IMFG] AS MFGKEY ON COMP.GMFGKEY] = MFGKEY.EMFGKEY]

 

LEFT JOIN ASSETMANAGEMENT_SEWER.ASEWERSERVICESTATUS] AS SERVSTAT ON COMP.VSERVSTAT] = SERVSTAT.TCODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.ASEWEROWNERSHIP] AS OWN ON COMP.SOWN] = OWN.PCODE]

 

WHERE COMP.>COMPKEY] > 1


With the SQL statement below

 

I can add a new column under select with

COMP.PIPETYPE AS PAC_NO,

 

But how do I change the values in this new column?

Can I use if-then statements / If PAC_NO = 'DI' then PAC_NO = '1234'

 

/*

SewerServiceLine

*/

SELECT COMP.*,

VAR.*,

UNITTYPE.PDESCRIPT] AS UNITTYPE_RESOLVED,

 

ADDRKEY.KCACITY],

ADDRKEY.KCAPOSTDIR],

ADDRKEY.KCAPROVINCE],

ADDRKEY.KCASTNAME],

ADDRKEY.KCASTNO],

ADDRKEY.KCASUFFIX],

STKEY.KDESCRIPT] AS SEGKEY_RESOLVED,

 

AREA.ADESCRIPT] AS AREA_RESOLVED,

SUBAREA.ADESCRIPT] AS SUBAREA_RESOLVED,

DISTRICT.RDESCRIPT] AS DISTRICT_RESOLVED,

LOC.>DESCRIPT] AS LOC_RESOLVED,

 

PIPETYPE.EDESCRIPT] AS PIPETYPE_RESOLVED,

SURF.>DESCRIPT] AS SURF_RESOLVED,

SIC.pDESCRIPT] AS SIC_RESOLVED,

SRVTYPE.VDESCRIPT] AS SRVTYPE_RESOLVED,

 

MFGKEY.MCODE] AS MFGKEY_RESOLVED,

 

SERVSTAT.EDESCRIPT] AS SEVRSTAT_RESOLVED,

OWN.>DESCRIPT] AS OWN_RESOLVED

 

FROM ASSETMANAGEMENT_SEWER.NCOMPSSL] AS COMP

LEFT JOIN BURNABY. VARSSL] AS VAR ON COMP. COMPKEY] = VAR.YCOMPKEY]

LEFT JOIN ASSETMANAGEMENT_SEWER.NSEWERSERVICETYPE] AS UNITTYPE ON COMP. UNITTYPE] = UNITTYPE.UCODE]

 

LEFT JOIN PROPERTY. ADDRESS] AS ADDRKEY ON COMP.YADDRKEY] = ADDRKEY.=ADDRKEY]

LEFT JOIN ASSETMANAGEMENT_STREET.NCOMPSEG] AS COMPSEG ON COMP.GSEGKEY] = COMPSEG.=COMPKEY]

LEFT JOIN ASSETMANAGEMENT_STREET.NSTREET] AS STKEY ON COMPSEG.NSTKEY] = STKEY.]STKEY]

 

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERAREA] AS AREA ON COMP.EAREA] = AREA.ECODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERSUBAREA] AS SUBAREA ON COMP.ESUBAREA] = SUBAREA. CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERDISTRICT] AS DISTRICT ON COMP.CDISTRICT] = DISTRICT.=CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.MSEWERLOCATION] AS LOC ON COMP.OLOC] = LOC.LCODE]

 

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERPIPETYPE] AS PIPETYPE ON COMP.YPIPETYPE] = PIPETYPE. CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERSIC] AS SIC ON COMP.SSIC] = SIC.[code]

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERSERVICETYPE] AS SRVTYPE ON COMP.YSRVTYPE] = SRVTYPE.]CODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.ESEWERSURFACECOVER] AS SURF ON COMP.USURF] = SURF.UCODE]

 

LEFT JOIN RESOURCES.IMFG] AS MFGKEY ON COMP.GMFGKEY] = MFGKEY.EMFGKEY]

 

LEFT JOIN ASSETMANAGEMENT_SEWER.ASEWERSERVICESTATUS] AS SERVSTAT ON COMP.VSERVSTAT] = SERVSTAT.TCODE]

LEFT JOIN ASSETMANAGEMENT_SEWER.ASEWEROWNERSHIP] AS OWN ON COMP.SOWN] = OWN.PCODE]

 

WHERE COMP.>COMPKEY] > 1

Did you try it with a small test query? As long as you don't do it in a production database "just giving it a try" is often the best way to find out.


Reply