Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Concat NULL yields NULL inside a Function

Concat NULL yields NULL inside a Function

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fabricio Dos Santos Antunes
    wrote on last edited by
    #1

    I need to use a function inside my database that need have the option Concat NULL yields NULL ON, however my database doesn't use that, so , I need to ensure that'll be ON when the function executes. But seens not possible to define that inside the function ( Set .. On, is not allowed ). There's any way to do that? :)

    S M Richard DeemingR 3 Replies Last reply
    0
    • F Fabricio Dos Santos Antunes

      I need to use a function inside my database that need have the option Concat NULL yields NULL ON, however my database doesn't use that, so , I need to ensure that'll be ON when the function executes. But seens not possible to define that inside the function ( Set .. On, is not allowed ). There's any way to do that? :)

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      assuming that you are using SQL server have a read of this. http://stackoverflow.com/questions/5702190/concatenate-null-value-columns-in-tsql[^] the first answer shows you how to do this with version prior to sql server 2012 and with sql server 2012.

      Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

      1 Reply Last reply
      0
      • F Fabricio Dos Santos Antunes

        I need to use a function inside my database that need have the option Concat NULL yields NULL ON, however my database doesn't use that, so , I need to ensure that'll be ON when the function executes. But seens not possible to define that inside the function ( Set .. On, is not allowed ). There's any way to do that? :)

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        So code around it, ISULL(FieldName,'') will do for text fields

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • F Fabricio Dos Santos Antunes

          I need to use a function inside my database that need have the option Concat NULL yields NULL ON, however my database doesn't use that, so , I need to ensure that'll be ON when the function executes. But seens not possible to define that inside the function ( Set .. On, is not allowed ). There's any way to do that? :)

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Microsoft have already stated[^] that the option to turn CONCAT_NULL_YIELDS_NULL off will be removed in a future version. You should probably be looking to update the database so that it works with this setting turned on.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          F 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Microsoft have already stated[^] that the option to turn CONCAT_NULL_YIELDS_NULL off will be removed in a future version. You should probably be looking to update the database so that it works with this setting turned on.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            F Offline
            F Offline
            Fabricio Dos Santos Antunes
            wrote on last edited by
            #5

            Yeah, we should start think about it here, thank you. The problem is that we're using that on the return of a XML. The error are on the XML return. to solve, before call the function we got to use this.

            SET CONCAT_NULL_YIELDS_NULL ON;
            GO

            This is our function

            CREATE FUNCTION Function_StripHTML(@Text NVARCHAR(MAX), @BreakLine BIT)
            RETURNS VARCHAR(MAX)
            AS
            BEGIN
            DECLARE @XML AS XML

            IF @BreakLine = 1
            BEGIN
            	SET @Text= REPLACE(REPLACE(REPLACE(@Text,'  
            

            ', CHAR(13)), '
            ',CHAR(13)), '
            ',CHAR(13))
            END
            ELSE
            BEGIN
            SET @Text= REPLACE(REPLACE(@Text, '
            ','
            '), '
            ','
            ')
            END

            SET @XML = CAST(('' + REPLACE(REPLACE(dbo.Function\_RemoveInvalidCharacters(@Text), '&', '&'), '<', '')+'') AS XML)
            
            SELECT
            	@Text=
            	(
            		SELECT
            			CASE WHEN LEFT(N.value('.', 'VARCHAR(MAX)'), 3) = 'br>' THEN
            				'<' + N.value('.', 'VARCHAR(MAX)')
            			ELSE
            				STUFF
            				(
            					N.value('.', 'VARCHAR(MAX)')
            					, 1
            					, CHARINDEX('>', N.value('.', 'VARCHAR(MAX)'))
            					, ''
            				)
            			END
            		FROM
            			@XML.nodes('x') AS T(N)
            		  FOR XML PATH('')
            		, TYPE
            	).value('.', 'VARCHAR(MAX)')
            
            RETURN LTRIM(RTRIM(@Text))
            

            END
            GO

            I'm sorry if the code looks confuse, was made for a coworker here. :-O

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups