Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query help

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-01-20 : 05:11:48


this is my query

SELECT @PLocationName = @PLocationName + ISNULL(CAST(LOCATION_ID AS VARCHAR) + '::' + LOCATION_NAME,'~~') + '~~'

getting output as

1501::USA~~1502::CANADA~~

want output to be like
1501::USA~~1502::CANADA

what needs to be modified in above query?

Kristen
Test

22859 Posts

Posted - 2010-01-20 : 05:32:03
Remove the

+ '~~'

from the end of your SELECT line
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-01-20 : 05:42:22
then am getting output as 1501::USA 1502::CANADA where ~~ is missing
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-20 : 06:01:27
Ah, sorry, I see now that you are concatenating several rows.

If you can start with @PLocationName being NULL, rather than "empty string", then:

SELECT @PLocationName = COALESCE(@PLocationName + '~~', '') + ISNULL(CAST(LOCATION_ID AS VARCHAR) + '::' + LOCATION_NAME,'~~')

should do the trick.

You will get "~~~~" whenever Location_ID or Location_Name is null
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-01-20 : 06:09:16
THANKS
Go to Top of Page
   

- Advertisement -