How do I use If Then Else logic using values from the current column and another column?
KD34XBR960
Posts: 2 New member
I tried using a Python script, but it doesn't recognize the current column:
def main(config):
if OtherColumn == "":
return CurrentColumn
else:
return ""
How do I reference the current column in a Python script? If this isn't possible, can this feature be added or is there another generator I can use? If not, it seems I could create a view that duplicates the CurrentColumn (e.g., CurrentColumnCopy) so I can reference the duplicated version of the CurrentColumn, but that seems like an odd way to handle this scenario.
How do I reference the current column in a Python script? If this isn't possible, can this feature be added or is there another generator I can use? If not, it seems I could create a view that duplicates the CurrentColumn (e.g., CurrentColumnCopy) so I can reference the duplicated version of the CurrentColumn, but that seems like an odd way to handle this scenario.
Tagged:
Answers
Are you able to provide some more specifics around your use case so I can try and create an example.
I don't think it would be possible to reference the current column as it would not exist when the data generator runs. It runs via INSERT statements and not UPDATE so the existing data is already gone by the time the python script is executed.
It may be possible to do via a view, or export from the database and then read in a file and manipulate that.
One thing I see in your code - you will potentially want to add a loop at the top of your code - the config argument loads in the entire dataset and you will ideally want to loop through each record/iteration within the entity to make your logic checks.
Hi @KD34XBR960
Glad to hear you got a workaround using views.
I would recommend posting your request on our UserVoice site. It allows users of our tools to post their feature requests direct to the developers and help shape the roadmap of our future releases.
Having a quick scan through previous requests I wasn't able to see a request matching yours but would invite you to create a request here:
https://redgate.uservoice.com/forums/936348-sql-toolbelt-essentials