Use a default value in variable if sql query doesn't return any rows

Issues related to label design (working with databases, data processing, RFID encoding etc.) and printing (from NiceLabel Express, NiceLabel Pro, NiceForm and NicePrint)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
Findan
Newcomer
Posts: 2
Joined: Thu Oct 22, 2020 8:07 am

Use a default value in variable if sql query doesn't return any rows

Post by Findan » Thu Nov 05, 2020 3:42 pm

Hi,

for my label, I have written custom sql queries in NiceLabel to get some specific values from my Access database and assign them to variables.
However, that query will not always return rows and since that would produce errors when you want to print and that's not very user friendly, I want to find a way around that.

In normal sql, there's the function isnull that takes a value to check and a value to return if that first one is null. That sadly doesn't exist for Access, only isnull that takes one parameter and returns a boolean.

Then there is nz() that does the same in Access that isnull does with two parameters in normal sql.

Now, obviously isnull(a, b) doesn't work with the database. Isnull does, but since I can't give that function any additional values, that's useless for me. And apparently nz(a, b) doesn't work either, atleast NiceLabel doesn't recognize it.

Am I missing something? Is there a fourth function that also works in NiceLabel?

User avatar
Kyleodonnell
NiceLabel Support
NiceLabel Support
Posts: 720
Joined: Mon Aug 28, 2017 3:07 pm

Re: Use a default value in variable if sql query doesn't return any rows

Post by Kyleodonnell » Thu Nov 05, 2020 4:04 pm

Findan,

you would most likely have to write a script that checks against the variables and if they blank or null, have it set the variable to some default value.

PAMO
Newcomer
Posts: 2
Joined: Mon Apr 12, 2021 9:53 pm

Re: Use a default value in variable if sql query doesn't return any rows

Post by PAMO » Wed Apr 14, 2021 9:28 pm

Kyleodonnell
Could you give an example of such a script

User avatar
Kyleodonnell
NiceLabel Support
NiceLabel Support
Posts: 720
Joined: Mon Aug 28, 2017 3:07 pm

Re: Use a default value in variable if sql query doesn't return any rows

Post by Kyleodonnell » Tue Apr 27, 2021 3:48 pm

PAMO

you can use a if/else statement
https://www.guru99.com/vbscript-conditi ... ments.html

Post Reply