Search code examples
sql-servervbscriptlocalization

Is it possible to un-localize MSSQL-results in VBS?


Sorry if I'm using the wrong terminology - I'm not into MSSQL or VBScript.

I have a given script implementing a SQL query containing

.. AND (rep.is_primary_replica is null or rep.is_primary_replica = ''True'' or rep.is_primary_replica = ''False'') ..

which returns no results on a German server only because rep.is_primary_replica seems to contain ''Wahr'' and ''Falsch'' instead of ''True'' and ''False''

This question is about an at least similar problem.

Unfortunately there is no wtf flag.

Is there a way to do that correctly?

Can I disable localization of string conversions? (in MS SQL Server? VBS?)


Solution

  • Don't let printed values in the script confuse you. There is an implicit conversion from original value to string which depends on the client's (VBScript in your case I think) locale.

    Type of the field is_primary_replica here must be bit if the rep is an instance of sys.dm_hadr_database_replica_states view.

    If this is the case, it's pointless to check a bit field is Null, or its value equal to True or False, there's no other possibility anyway.

    It appears that you can safely remove this condition from the query.

    If you insist to include it, use number literals instead.

    AND (rep.is_primary_replica is null or rep.is_primary_replica = 1 or rep.is_primary_replica = 0)
    

    This is the proper way to query a bit field. With this way the server's or client's locale configuration won't cause any problems.