Wednesday, February 3, 2021

Typical Testing Day

 

            Recently I came across a situation where I need to find whether a particular column has an integer value or varchar...there could be many ways to find the outcome however found the below query which is very simple.

Let us say we have a table called EMPLOYEE and ID is a varchar column, I need to find records which as integer or char.

SELECT * FROM EMPLOYEE

                    WHERE ID LIKE '%[^0-9]%' -- Looks for 0-9

                     OR ID LIKE '_%-%' -- Looks for the '-' other than 1st position.


 

If you ever come across a situation wherein you have to quickly modify the list of things in the SQL query...probably either you would have copied that text into excel added some formula to get the desired format. Instead, we can use this little trick in the SQL Query window itself...

   Hold ALT and mouse left click...you will notice vertical line '|' each string like below after that we can add the same character before or after the vertical line.





Hope it helps