bibi92
asked on
error on cast command
Hello,
I try to execute this command :
SELECT a.name +'|'+ CAST(b.mirroring_role AS varchar(15))FROM sys.databases A INNER JOIN sys.database_mirroring B ON A.database_id=B.database_i d WHERE mirroring_role is null or mirroring_role=1
but the result is NULL, how can I add the name master|null.
Thanks
Regards
bibi
I try to execute this command :
SELECT a.name +'|'+ CAST(b.mirroring_role AS varchar(15))FROM sys.databases A INNER JOIN sys.database_mirroring B ON A.database_id=B.database_i
but the result is NULL, how can I add the name master|null.
Thanks
Regards
bibi
SELECT a.name +'|'+ ISNULL(b.mirroring_role,'N ULL')
ASKER
But if mirroring_role is not null, is that query will run successfully?
Thanks
bibi
Thanks
bibi
ASKER
I try to execute it and there is an error :
Conversion failed when converting the varchar value 'NULL' to data type tinyint.
Conversion failed when converting the varchar value 'NULL' to data type tinyint.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is mirroringrole a tinyint field? If so, you need to use:
SELECT a.name +'|'+ ISNULL(CAST(b.mirroring_ro le AS varchar(15)),'NULL')
the ISNULL function will simply provide an alternative value if the record is null. If it isn't null, it will use the first argument of the function.
So, ISNULL('value','NULL') will return 'value', but ISNULL(NULL,'NULL') will return 'NULL'
SELECT a.name +'|'+ ISNULL(CAST(b.mirroring_ro
the ISNULL function will simply provide an alternative value if the record is null. If it isn't null, it will use the first argument of the function.
So, ISNULL('value','NULL') will return 'value', but ISNULL(NULL,'NULL') will return 'NULL'
or use
SELECT a.name +'|'+ isnull(CAST(b.mirroring_ro le AS varchar(15)),'') ...
SELECT a.name +'|'+ isnull(CAST(b.mirroring_ro
after reading the question, I see that you want 'NULL' instead of ''
so try my posts with 'NULL' instead of ''
so try my posts with 'NULL' instead of ''
ASKER
Thanks bibi