SQLTeam.com | Weblogs | Forums

TSQL - Function not working


Hi everyone.
I'm trying to implement a condition to not let the user add/update any document if a specific field if he's null or empty. But, unfortunately, it's not working.

Can you find the error?

IF @object_type='13' and (@transaction_type='A' or @transaction_type='U')
		SELECT @SeasonOINV = OINV.U_Season FROM OINV WHERE DocEntry = @list_of_cols_val_tab_del;
		IF (@SeasonOINV IS NULL or @SeasonOINV = ' ')
			SET @error = 1000;
			SET @error_message = 'SAP ERROR: Must choose a season - Maybe Item doesn''t have season defined or It''s a service Doc. Please fill any value.';
			SELECT @error, @error_message



Try this

IF (LTRIM(RTRIM(ISNULL(@SeasonOINV,''))) = '')


When you say:

it's not working.

What do you mean, exactly?

FWIW there are problems:

SELECT @SeasonOINV = OINV.U_Season FROM OINV WHERE DocEntry = @list_of_cols_val_tab_del;

If more than one value is returned from the select, your variable will have the last value returned, whatever that is.
Even if there is only one such value today, there may be more tomorrow. First then, ensure that this select can only return one result. e.g. add TOP(1) to the SELECT.

Also, when debugging code like this, put a PRINT @SeasonOINV after the select to see what you have received.