Bug in "SELECT @sResult = CASE_WHEN LEN(@sResult) = 0 THEN col ELSE @sResult + ',' + col END "

Hello, I want to
report a bug in all versions of SQL
Server
The database I
set collation: SQL_Czech_CP1250_CI_AS
The following script
will return 3:
DECLARE @sResult nvarchar(4000) -- variable to store the resulting string
DECLARE @tab table(col varchar(10) , id int)
--DECLARE @tab table(col nvarchar(10) , id int) -- It works well, but the column in the database is varchar
SET @sResult = ''
insert into @tab(col, id) values ('1',1)
insert into @tab(col, id) values ('2',2)
insert into @tab(col, id ) values ('3',3)
SELECT @sResult = CASE WHEN LEN(@sResult) = 0 THEN col ELSE @sResult + ',' + col END
FROM
@tab
ORDER BY id,col -- works incorrectly
--ORDER BY col -- works incorrectly
--ORDER BY id -- works correctly
SELECT @sResult
When I set
the database Collation: Czech_CI_AS, the script
returns the correct result: 1,2,3.
Stanislav Skalický
pracovník IT
EFG CZ spol. s r.o.
Na Jarově 4, 130 00 Praha
Tel.:     +420 222 746 337
Mobil: +420 775 864 814
Czech Republic

That is not a good way to concatenate a comma delimited string. There are known issues with the method. 
DECLARE @sResult nvarchar(4000) -- variable to store the resulting string
DECLARE @tab table(col varchar(10) , id int)
SET @sResult = ''
insert into @tab(col, id) values ('1',1)
insert into @tab(col, id) values ('2',2)
insert into @tab(col, id ) values ('3',3)
SELECT @sResult = CASE WHEN LEN(@sResult) = 0 THEN col ELSE @sResult + ',' + col END
FROM
@tab
-- ORDER BY id,col -- 1,2,3
-- ORDER BY col -- 1,2,3
-- ORDER BY id -- 1,2,3
-- ORDER BY col COLLATE SQL_Czech_CP1250_CI_AS -- 3
-- ORDER BY id, col COLLATE SQL_Czech_CP1250_CI_AS -- 3
-- ORDER BY col COLLATE Czech_CI_AS -- 3
-- ORDER BY newid() -- 3
-- no ORDER BY 1,2,3
SELECT @sResult
Use the XML PATH method instead:
http://www.sqlusa.com/bestpractices/training/scripts/commadelimitedlist/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Similar Messages

  • Lightroom Bug: with GoPro Hero4 Silver Lens Profile, crop settings do not sync properly in Lightroom 5.7.1 when Constrain To Warp is checked

    I was having a bit of difficultly in getting crop settings to properly sync in Lightroom 5.7.1 (running on OS X 10.10.1) when Constrain to Warp was checked.  This appears to be a bug in the latest version(s) of Lightroom that include(s) the GoPro Hero4 Silver Lens Profile settings.  I'm working with a lot of files from a GoPro Hero4 Silver camera shot in the time-lapse / interval timer mode.  All of them are horizontal with the same resolution (and dimensions).  I've tried various sequences to get this to work in terms of using Auto-Sync, resetting the settings on all images except one and then copy and pasting settings, etc, though the crop is not properly syncing regardless of what I do.
    Here's are instructions of how to duplicate this issue (there are some extra details/steps here, though this should be clear enough to produce the same result):
         1.  in the Develop settings for a single selected image, go to Lens Corrections, click to Enable Profile Corrections (in the Profile tab), and then pick the GoPro Hero4 Silver Edition (Adobe Profile) if it is not automatically chosen for you (if you are using files from a Hero4 Silver camera).  After this, click on the Manual tab, and set the Scale setting to 76.  (as you will see, you now have the full horizontal width of the image that was getting cropped off, though you do see white around the edges that have been warped/shaped to correct the fisheye distortion)
         2.  Press the R key (or click on the Crop Overlay tool just below the histogram).  Change the Aspect option to Custom.  Click to unlock the lock next to it (this seems to re-lock after setting to custom even if it was locked before).  Place a checkmark next to the Constrain To Warp option.  (At this point, you'll see the image gets cropped back to an approximately 4:3 ratio and the full horizontal width is not included in the cropped area)  Click the upper right most corner of the crop area and drag as much to the right and top as it lets you go.  Do the same for the lower left corner, dragging it as far to the bottom left as you can go.  (Now, you will see that your cropped area is the maximum rectangular width and height you can select without getting any of the excessive white area)  Click the Close button (or press R again) to leave the crop overlay tool.
         3.  Press G to go back to the grid of images.  Make sure the image you just adjusted the settings for is the only one selected.  Right click on it, go to Develop Settings, and click Copy Settings.  Click Check All on the window that appears and then click Copy.
         4.  De-select the image you were working on.  Select multiple other images in the grid.  Right click on one of these, go to Develop Settings, and click Paste Settings.  (at this point, you will see their aspect ratio has become more panoramic than the 4:3 aspect ratio the images previously were)
         5.  De-select these images.  Select one of these image, and then press D to go to the Develop settings for this image.  Press R to go to the Crop Overlay tool.  Here you will see the bug where the crop was not properly copied over from the first image.  The selected area is smaller than the full width and height available to crop.
    It seems that the bug is that Lightroom is only copying the aspect ratio (and the other settings), but not the actual crop selection.
    I just thought of a workaround that I've tested and can confirm works (and will also work in a slightly different workflow than above).  In step 1 above, for the Model (and Profile), manually pick the "GoPro Hero4 Black Edition" or the "GoPro Hero3-Silver Edition".  If using the "Hero3-Silver" setting, the Scale (also in step 1 above) need only be set to 79 (rather than 76 for the Hero4 profiles).  By picking one of these Lens Profiles and doing everything else the same as the other steps above, the crop settings do copy and paste properly.  This does also appear to work properly when selecting the "GoPro Hero3-White Edition" Lens Profile, with a Scale setting of 75, which yields a slightly more rectilinear image (with a wider aspect ratio -- almost, but not quite 16:9).
    While this isn't too big of deal as it does work by picking one of the other lens profiles (and the Hero4 Black Edition profile appears to make the same exact correction to the image), this was incredibly frustrating last night to notice that some files had the proper horizontal field of view / crop and others didn't, and other users may experience this or not even notice their crop is not copied properly (as, depending on one's composition and image, it's not extremely obvious with such a wide view).
    I hope this discovery helps someone else and provides feedback for Adobe to correct this issue in the next version of Lightroom 5.
    On a separate, additional note for Adobe:  Please allow the crop overlay tool to "crop" an image to a size that is larger than the original dimensions of the image.  This would allow for one to retain maximum original sharpness in the center of the image when using the Lens Profile tool to correct, or "de-fish" a lens, without having to scale the image down with the Scale option on the Manual tab of the Lens Corrections settings.  For example, when I do the above process selecting the Hero3-White Edition profile, my final image dimensions are 3840 by 2257 pixels, reducing the size of the image in the center by 25%.  If the tool allowed one to crop/scale a larger image size, and I kept the Scale option of the Lens Corrections settings at 100 rather than 75, my final image dimensions would be 5120 by 3009 pixels (larger than the 4000 by 3000 pixel dimensions of the original image which the tool now limits me to).  Yes, the edges would be a little softer but the center would retain the original detail.  (this is essentially what the Calculate Optimal Size button found in the Hugin open source software does, when using it on a single image for lens transformations/corrections)

    Can you zip up a few of your GoPro images, upload them to dropbox.com and post a share link, here, so others can experiment with them, or do you mean this issue is global to all camera models?

  • How do I select and email a whole lot of photos on my iPad from my iPad emails? It seems I have to go into Email and then insert one photo at a time? Isn't there a way to select all in the photos and then email the batch.?

    How do I select and email a whole lot of photos on my iPad from my iPad emails? It seems I have to go into Email and then insert one photo at a time? Isn't there a way to select all in the photos and then email the batch.?

    Actually, you can email up to 5 at a time from the Photos app. Select any more and the email share option will not appear.
    If you explain why you need to email large numbers of photos, we might be able to offer an alternative.

  • HT1947 After updating My Apple TV to 5.1 I can browse music library using the Remote app on my iPhone and iPad but cannot select a song to play. Is someone else having the same problem?

    I have updated my Apple TV to 5.1. Using the Remote app on my IPhone and iPad I can browse the music library on the Apple TV but I cannot select a song to play. Has someone else the same problem?
    Mats

    I think I found the reason. On my iMac that is hosting the music library a song already was playing. This seems to block out me from selecting another song though my Apple TV.
    Mats

  • My macbook pro won't sleep - if I select sleep it does so initially, then the disc-drive appears to kick in and it comes back to life.  It also won't turn off (again, the disc drive kicks in) unless you hold the power-button down for a long period.

    My macbook pro won't sleep - if I select sleep it does so initially, then the disc-drive appears to kick in and it comes back to life.  It also won't turn off (again, the disc-drive kicks in) unless you hold the power-button down for a long period.  Help?

    Hi a,
    Try an SMC Reset: http://support.apple.com/kb/HT3964

  • Can log into FaceTime it then asks what I want to use as contact so I select email address it says verifying then asks for apple if again and just keeps repeating the process

    Can log into FaceTime it then asks what I want to use as contact so I select email address it says verifying then asks for apple if again and just keeps repeating the process

    Hello Magsbingham
    You may find the troubleshooting steps in the article below helpful.
    iOS: Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    -Griff W.

  • I have been unsuccessful merging serval pdf files into one file.  I select the Sidebar for both pdfs, then drag one pdf on top of the other and Save the Version.  When I open the file I think I have saved, it shows only the original pdf.  Advice would be

    I have been unsuccessful merging serval pdf files into one file.  I select the Sidebar for both pdfs, then drag one pdf on top of the other and Save the Version.  When I open the file I think I have saved, it shows only the original pdf.  Advice would be appreciated.  Thank you.

    wouldnt it be easier if you could do something like this?
    https://discussions.apple.com/thread/3392535

  • Just upgraded to iOS5 on ipad2 and now have all my old emails to delete. Is there a way to select all like in trash and then delete all?

    just upgraded to iOS5 on ipad2 and now have all my old emails to delete. Is there a way to select all like in trash and then delete all?

    Thanks for the feedback, the question is that it will syn all the folders that I have checked, and its total up to 6000 photos which was taking me one whole day to syn. I am seeking is there away that what have already in my Iphone will not be delected if I did not checked on the next syn, and only add in the new album that was checked.

  • BUG JSF Select Item not binding properly

    Dear Oracle,
    I'm running JDeveloper 10g version 10.1.3.0.3.3412 early access 1. If you create a HTMLMenu1 select list in a JSF Page and use the properties dialog to bind the values to a backing bean, the binding get's lost and the page doesn't call the value binding. What's more, if you try to rebind the values using the dialog, JDeveloper repeatedly inserts a new SelectItems tag for the menu.
    For example, if you create the SelectMenu1 and then use the dialog to bind the selectItems to a backing bean property, you will end up with code something like this:
    <h:selectOneMenu binding="#{backing_showFactory.selectOneMenu1}"
    id="selectOneMenu1"
    valueChangeListener="#{backing_showFactory.selectFactoryEvent}"/>
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems1}"
    id="selectItems1"/>
    Now, click on the newly created menu item in the design window of the JSP editor and bring up the properties dialog. You will see that the value binding is blank. If you reenter the value binding information, JDeveloper creates a new tag so you end up with the following:
    <h:selectOneMenu binding="#{backing_showFactory.selectOneMenu1}"
    id="selectOneMenu1"
    valueChangeListener="#{backing_showFactory.selectFactoryEvent}"/>
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems2}"
    id="selectItems2"/>
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems1}"
    id="selectItems1"/>
    Each time you repeat the process, JDeveloper creates another tag:
    <h:selectOneMenu binding="#{backing_showFactory.selectOneMenu1}"
    id="selectOneMenu1"
    valueChangeListener="#{backing_showFactory.selectFactoryEvent}"/>
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems3}"
    id="selectItems3"/>
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems2}"
    id="selectItems2"/>
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems1}"
    id="selectItems1"/>
    Either way, if you clean up the JSF page with the spurious tags, the value binding (in the example above backing_showFactory.allFactories), is never called.

    Yes - this really is a bug. Any changes to make to the selectItems tag through the properties dialog rewrites the tag source code to seperate the selectOne tag and the selectItems tag. For example, before you use the dialog, you tag code could look like this:
    <h:selectOneMenu binding="#{backing_showFactory.selectOneMenu1}"
    id="selectOneMenu1">
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems2}"
    id="selectItems2"/>
    </h:selectOneMenu>
    After the use of the dialog the code will be rewritten as:
    <h:selectOneMenu binding="#{backing_showFactory.selectOneMenu1}"
    id="selectOneMenu1"/>
    <f:selectItems value="#{backing_showFactory.allFactories}"
    binding="#{backing_showFactory.selectItems2}"
    id="selectItems2"/>
    Notice, the tags are now seperated instead of the selectItems tag being encased in the selectOneMenu tag.

  • Does FCE/FCP have a bug in selecting frames?

    I am discovering that when I need to go down to the frame level and edit the cut precisely (i.e., cut precisely on an exact frame -- who doesn't?!) that FCE sometimes misses out on a frame by one. Either too early by one frame or too late. And it's hard to judge. I just have to play back the edited cut to see what happened and then it's a hassle trying to jiggle just one frame.
    Is this a bug or am I doing something wrong? Editing in NTSC DV in the sequence.
    (By the way, is there a method where I can just COPY one frame, and PASTE the same frame back?)

    Hi Tom,
    Thanks for the Freeze Frame tip.
    I am already using arrow keys. It just seems not to be selecting the right frame for cutting.
    So, my routine:
    Move to the part where I want to cut, using mouse, and then arrow keys.
    I would then use "m" to set a marker.
    Then I would select the footage and snap it to the marker.
    I sometimes set ins and outs on the sequence and Replace footage like that, but often use the marker method above.
    That is where I am getting single-frame errors, either one frame too early or too late.
    Maybe a question is: Do I set the marker at the end of the footage before the cut, or the first frame of the footage that I am replacing?
    Any suggestions appreciated.

  • BEx Analyzer bug in selection mask when selectin month values?

    Hi Gurus,
    I´m working with NW BI 7.0 and using BEx Analyzer 7.X (based on 7.20, Support Package 5, Revision 1776).
    In a query I want to do a selection within a selection mask for the Cal/Month variable (0Calmonth InfoObject).
    The values for months are appearing in correct order for example for the years from 2009 - 2011.
    But for the last three month values the year description appears always wrong.
    It shows always the year for the next years.
    Its like this:
    Jun 2009
    Jul 2009
    Aug 2009
    Sep 2009
    Oct 2010
    Nov 2010
    Dec 2010
    Jun 2010
    Jul 2010
    Aug 2010
    Sep 2010
    Oct 2011
    Nov 2011
    Dec 2011
    Jun 2011
    Jul 2011
    Aug 2011
    Sep 2011
    Oct 2012
    Nov 2012
    Dec 2012
    Is this a bug?
    The values are appearing correct in query results after selecting for example Dec 2012 and executing the query (Dec 2011 appears correct in query results).
    Thanks in advance.

    Thanks! I checked it, but the appearance of months and order is okay in T247.
    Any other ideas?
    I thought I read somewhere that this is a bug but can´t remember where I found that bug hint.

  • A bug auto-select mode + filtered by type layers

    In addition to this: http://forums.adobe.com/message/4302940#4302940
    When selecting multiple layers: 1. click > 2. "draw" a rectangle on the canvas to select desired layers > 3. release to submit selection
    The bug happens on step 2: the selection rectangle is not drawn correctly, at some point it freezes with certain size, so there is no visual confirmation on the canvas what will be selected.

    That's an interesting one, Thanks for letting us know!
    I've passed it on.

  • Bug with selection tool in Photoshop CS

    Hi there,
    I find a bug with photoshop.
    I work on video editing, so I usually create some image with not square pixel. In DV for exemple, we use 1,066 pixel ratio.
    So I create a layer in full screen for DV editing (720*576 pixels for PAL in Europe) with 1,066 pixel ratio.
    If I want to delete a area with 720*576 ratio, I use the selection tool and I select (keep the ratio 720*576) ... but the area wich I delete Is not really the correct ratio 720*576 !! Because, If I create a layer with the object tool (create a rectangle) with the correct ratio 720*576, It isn't the same shape as my old area.
    So I think there is a bug ... isn't it ?
    PS : sorry for my english, but I'm french.

    I have test this problem with a friend on a CS3 version.
    There is the same problem !
    But we don't have the CS4 ... anybody want to test this ?

  • BUG : Date Selecter

    The date selecter appears to have a bug. The last week of the month of October does not permit you to pass the selected day.
    In the calendar pop up. If the last week of October is
    SUN MON TUE WED THU FRI SAT
    27 28 29 30 31
    any day selected other than the Sunday Date (Oct 27 in this case) will return the previous day
    so if you select 31 then the date that is passed is October 30. like wise if you select 29 then October 28 is returned. Why is this? This is only the case for October and for any year.
    Can the JDeveloper team verify that this is the case and that this is a bug. I am using Jdeveloper 9.02.
    Thanks,
    Joe

    The problem seems to be dealing with going from Daylight Savings time to Standard time. The last Sunday of October we roll the clocks back an hour (hence you have a 25 hour day). Now the code forgot about this fact because it increase every day by a time of 24 hours...Hence the last week of October is always off a day (or an hour which is the previous day).
    They should have used something like:
    Calendar.add(Calendar.DAYS,1);
    And added a day and not 24 hours.
    instead of adding 24 hours. I have not verified April where the first Sunday of the Month we jump ahead an hour and have a 23 hour day. Anyway, I will add the changes to another class and have the calendar.jsp point to the new bean. OTherwise the picker is a good implementation.
    Thanks,
    Joe

  • BUG: Disabling 'Select All | Select None' for af:tableSelectMany

    I have a simple af:table that incorporates an af:tableSelectMany. Within the af:tableSelectMany I have the disabled property bound to my view's backing bean like this disabled="#{myBackingBean.selectManyDisabled}". The backing bean then returns true or false based on whether the user should be able to change the selection in the table.
    When the disabled property is set to true, the table's "select" column is displayed appropriately. The checkboxes are grayed out and the user cannot change their state by clicking on them. However, the Select All and Select None links are still shown at the top of the table and still are active. Clicking one of these links changes the selection state for this items in the table. Shouldn't these links be disabled too? Has anyone else found a reasonable solution to this bug?
    Thanks,
    Jim

    Unfortunately that does not fit my usecase.
    The Select column always needs to be shown because the selection state of an entry in the table represents that entry's inclusion or exclusion within a higher level object. It is important to show the user this information. There are just some cases when we do not want to allow the user to change this information. (Specifically when showing historical data).
    I did consider not rendering the af:tableSelectMany as shown in that sample, but then I would have to build my own "Select" column that would be rendered whenerever the af:tableSelectMany was not rendered. In my own column I would have to place disabled check boxes to mimic the display.
    At this point I have developed a work-around solution. In the af:table that contains this af:tableSelectMany component I have the selectionState property bound to my backing bean as well as having the selectionListener bound. When I receive the SelectionEvent notification, I rebuild the selectionState RowKeySet to remove any effect of the Select All or Select None. The result is that the check boxes simply "blink" but always remain as they should be. It's a hack, but it works.
    It would be much better if the Select All and Select None links were not displayed or were disabled. I really feel this is a bug since disabling the af:tableSelectMany does properly draw the checkboxes in a disabled state. They just forgot to deal with the two links.
    Jim

Maybe you are looking for

  • DVI connection to Samsung 226BW

    I have a problem with my new Mac Pro (2,8 Ghz) and a Samsung 226BW: when i try to connect the monitor using the DVI cable that was inside the monitor case, it doesn't work. If i connect the monitor with the VGA cable it works. What's the problem? Do

  • Back Ground Jobs for ESS/MSS

    Hi, I would like to know all the back ground jobs to be scheduled for ESS/MSS. As all the data updated in the portal as to reflect in r/3 system and all the data updated in r/3 system to portal. Regards Vish

  • Advice on upgrading to 10.5, & windows compatibility

    I am just getting used to my iMac, and my problem is I'm going Virtual PA home-based and need advice on what software to use to be compatible to all computer users, (etc windows XP, 98, Vista) and also on voice digital transcription, sorry for being

  • Alv programming

    Hi , can we insert data into database using ALV reporting?

  • BW on HANA Trial - Unable to Terminate Instance

    I'm trying to terminate SAP BW over HANA instance but it gives me a timeout Error: I need to terminate it in order to restart the solution. Regards.