Copy codeThe Code is as follows: CREATE function getcolor
(@ Varchar (50), @ 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
Well id = @ well ID and horizon = @ horizon and color is not null
) Aa
Set @ SQL = substring (@ SQL, 1, len (@ SQL)-1)
Return @ SQL
End
I found that the set @ SQL = substring (@ SQL, 1, len (@ SQL)-1) Statement sometimes reports an error because @ SQL is using substring, sometimes it is a Null String
In the function, how can I determine whether @ SQL is empty before substring?
If @ SQL is not null and len (@ SQL)> = 1
Set @ SQL = substring (@ SQL, 1, len (@ SQL)-1)
Else
...
Copy codeThe Code is as follows:
If (@ SQL is not null)
Set @ SQL = substring (@ SQL, 1, len (@ SQL)-1)
Return @ SQLCopy codeThe Code is as follows: if isnull (@ SQL, '') <>''
Set @ SQL = substring (@ SQL, 1, len (@ SQL)-1)
"Select * from db where img is not null" is the content that selects all img not empty.
"Select * from db where img is null" this is to select all the content with the img being empty.
If you want the SQL statement to determine whether the value is null, a default value can be used.
SELECT top 1 isnull (Yu_Yse_Commodity_KD, 0) FROM [Yu_Records]