How to realize the judgement of non-empty string in sql server
Today, I will talk to you about how to achieve string non-empty judgment in sql server, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
The code is as follows: CREATE function getcolor (@ well sign varchar (50), @ horizon varchar (50)) returns varchar (200) as begin declare @ sql varchar (2000); set @ sql=''-- distinct select @ sql=@sql+ color +', 'from (select distinct color from yourtablename where sign = @ well sign and horizon = @ horizon and color is not null) aa set @ sql=substring (@ sql,1,len (@ sql)-1) return @ sql end
I found that the sentence set @ sql=substring (@ sql,1,len (@ sql)-1) sometimes reports an error because @ sql sometimes has an empty string when using substring. How can I tell whether @ sql is empty before substring in the function? If @ sql is not null and len (@ sql) > = 1 set @ sql=substring (@ sql,1,len (@ sql)-1) else... The copy code is as follows: if (@ sql is not null) set @ sql=substring (@ sql,1,len (@ sql)-1) return @ sql copy code as follows: if isnull (@ sql,'')''set @ sql=substring (@ sql,1,len (@ sql)-1)
"select * from db where img is not null" this is to select all the content whose img is not empty "select * from db where img isnull" this is to select all the content whose img is empty. If you want to make the SQL judgment value null, you can use SELECT top 1 isnull (Yu_Yse_Commodity_KD,0) FROM [Yu_Records].
After reading the above, do you have any further understanding of how to realize the string non-null judgment in sql server? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.