TRY CAST and setting the type according to destination column

Hi,
I am loading data from different sources. I have to do data quality checks for data I am loading into destination. For Decimal Values I have destination data types Decimal(28,2) and Decimal(28,6) 
I would like to check the source data and covert the type according to destination column. How can I use the try cast in this scenario?
SELECT TRY_CAST(REPLACE('100,500.000',',','') AS DECIMAL(28,2))
this statement will convert every thing to two decimal places. but if destination column is decimal(28,6) i would like to convert it to 100500.657899
What is the best way of doing it?
MH

Hi MH,
According to your description, you need to CAST and setting the type according to destination column which data types is Decimal(28,2) and Decimal(28,6), right?
"this statement will convert every thing to two decimal places. but if destination column is decimal(28,6) i would like to convert it to 100500.657899" If in this case, then there are different data types on the same column which is not
supported in current version. So as per my understanding, there is no such a functionality to achieve your requirement. What we can do is convert to corresponding datatype (Decimal(28,2) or Decimal(28,6)), and then convert it to nvarchar datatype.
CREATE TABLE #TEMP(A NVARCHAR(50))
INSERT INTO #TEMP VALUES('1538.21'),('1635.326541'),('136.235')
SELECT
A,
CASE
WHEN (LEN(RIGHT(A,LEN(A)-PATINDEX('%.%',A))))>2
THEN
CAST(A AS DECIMAL(28,6))
WHEN (LEN(RIGHT(A,LEN(A)-PATINDEX('%.%',A))))<=2
THEN
CAST(A AS DECIMAL(28,2))
END AS B,
CASE
WHEN (LEN(RIGHT(A,LEN(A)-PATINDEX('%.%',A))))>2
THEN
CAST(CAST(A AS DECIMAL(28,6)) AS VARCHAR(99))
WHEN (LEN(RIGHT(A,LEN(A)-PATINDEX('%.%',A))))<=2
THEN
CAST(CAST(A AS DECIMAL(28,2)) AS VARCHAR(99) )
END AS B2
FROM #TEMP
DROP TABLE #TEMP
Regards,
Charlie Liao
If you have any feedback on our support, please click
here.
Charlie Liao
TechNet Community Support

Similar Messages

  • I've recently upgraded to Lightroom5.7.1 and now when I try to import photos a window pops up saying 'the photos can't be imported 'cos the files can't be read'. I had no problems before upgrading. I have Windows8 & can't find any 'app' which sets the typ

    I've recently upgraded to Lightroom5.7.1 and now when I try to import photos a window pops up saying 'the photos can't be imported 'cos the files can't be read'. I had no problems before upgrading. I have Windows8 & can't find any 'app' which sets the type of files I can import. Any help appreciated.

    Well, think about it. This is a Lightroom forum. We are here to answer questions about Lightroom and how to solve problems in Lightroom. Your permissions issue is an operating system issue, not a Lightroom issue. I didn't mean to be sarcastic. But there are plenty of Internet resources that will answer that question.
    I just went to Google and typed in "change disk permissions", and there are links for the Mac as well as for Windows listed. There's no sense in me rewriting instructions that are already available.

  • On my iphone, icloud is set to an apple id that i no longer use and i keep getting asked to enter a password. Cannot remember the password. When i try to re-set the password, it sends a email to a address no longer used. Will not accept any dob i enter

    I have icloud on my phone with an apple id that I no longer use. I keep getting asked to enter the password for this ID. However I can't remember the password.
    When I try to re-set the password, a e-mail will be send to an address I no longer use and can't access.
    I then try to answer the security questions, but the date of births I enter are not accepted
    Any ideas?
    Paul

    Welcome to the Apple community.
    This feature has been introduced to make stolen phones useless to those that have stolen them.
    However it can also arise when the user has changed their Apple ID details with Apple and not made the same changes to their iCloud account/Find My Phone on their device before upgrading to iOS 7, or if you restore from a previous back up made before you changed your details.
    The only solution is to change your Apple ID back to its previous state with Apple at My Apple ID, verify the changes, enter the password as requested on your device and then turn off "find my phone".
    You should then change your Apple ID back to its current state, verify it once again, delete the iCloud account from your device and then log back in using your current Apple ID. Finally, turn "find my phone" back on once again.
    This article provides more information about Activation Lock.

  • Why can't I just right click on the thumbnails and set the websites I want?

    I love the thumbnail idea, but why can't I just right click on the thumbnails and set the websites I want?
    Why do i have to wait for a recent one to come up?
    Of the 9 available, I would like to set 6 to website i can input by right clicking it and leave the rest for the recently visited.
    I ho[e you include that feature in your next update.
    Thank you
    P.S. 2 more issues
    1. Firefox is the only browser that always give me trouble attaching files in gmail. I still use firefox for all browsing but for mail attachments, I use others. And yes, I have done the "Clear cookies, reset, reinstall, clear cache, etc etc etc... none worked for more than a few days. no such problem with other browsers.
    2. Your new updated search bar (Top right hand corner) is nice but can be very irritating for the following reason:
    I like to highlight - copy (a word or phrase) - and paste it in the search bar. was fine with the older version, but now as soon as I right click to past, the menu pops up for me to select a search engine. Very irritating since I have yet to paste the copied word or phrase. I rather paste it and then have the option to click on the drop down menu. If you see this as not something masses would want, please place an option in setting for us to stop the suggestion for search engines coming up automatically when we try to right click in the side search bar to paste.

    You can change the order of the boxes on the about:newtab page and drag an item to a different tile to pin it to that position or you can remove a website by clicking the close X to block that URL.
    You can drag a bookmark or history item and drop them in a tile on the about:newtab page to pin them and have your own favorites sites showing.
    Changes made manually on the about:newtab page are stored in prefs that you can find on the about:config page.
    *browser.newtabpage.pinned stores websites that you have pinned to a tile.
    *browser.newtabpage.blocked stores websites that you have removed by clicking the X button in a tile.
    So you can reset those prefs via the right-click context menu to reset changes made to the about:newtab page.
    *http://kb.mozillazine.org/about:config

  • HT2508 My amp has an USB input but when I attach my mac pro to it, and set the input to the USB setting, no sound comes out. I looked at the system settings, but none of them produce a different outcome. How can I send the music through the USB out to USB

    My amp has an USB input but when I attach my mac pro to it, and set the input to the USB setting, no sound comes out. I looked at the system settings, but none of them produce a different outcome. How can I send the music through the USB out to USB in?

    AFAIK cameras offer their own built-in format utility for inserted SD cards.  You should use that.  Otherwise, refer to the manual that came with your camera to determine precisely how your SD cards need to be formatted to work properly.  Personally, I'd suggest Partition Scheme: MBR, and Filesystem: FAT32.
    Try to limit the number of formats you perform on the SD cards, though, as you're reducing their lifespan.  I believe formatting causes re-writes to a portion of the SD card that has fewer read/write cycles than the rest of the card as a whole.

  • An error has occurred. Please try again, and if the problem persists, contact your help desk or system administrator. (Error 3000)

    Hi,
    When i open my Password Reset portal then provide Username credentials in text box and click on next then asked the Securites Question Answers to me,i provide the correct Answers to the securites Question after this password reset portal asked
    me New Password and Confirm Password then click on next for resetting the password then gives below Error only for 2 Users. and all other users are working fine.
    An error has occurred. Please try again, and if the problem persists, contact your help desk or system administrator. (Error 3000:)
    Regards
    Anil Kumar

    Anything in the event log?

  • TS3474 iTunes has detected an iPod that appears to be corrupted. You may need to restore this iPod before it can be used with iTunes. You may also try disconnecting and reconnecting the iPod.

    What do I do about this message? I've restored it 3 times, but this message still comes up, and i cannot put music on it now.
    iTunes has detected an iPod that appears to be corrupted. You may need to restore this iPod before it can be used with iTunes. You may also try disconnecting and reconnecting the iPod.

    Sounds like your iPod is broken. Take it to Apple or someone else who repairs iPods and see if you can get it fixed, or get it replaced.

  • When i try installing photoshop from adobe creative cloud it says: fail on update, try again, i try again and says the same

    When i try installing photoshop from adobe creative cloud it says: fail on update, try again, i try again and says the same, any help?

    Try this link; follow the instructions carefully: Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
    And also a troubleshooting page: https://helpx.adobe.com/creative-suite/kb/troubleshoot-install-logs-cs5-cs5.html
    Benjamin

  • I have the latest Creative Cloud versions of Lightroom and Lightroom Mobile on my Ipad. On my desktop I have created a collection which I have put in a custom order. On my Ipad I go into that collection and set the order to custom order, which I presume m

    I have the latest Creative Cloud versions of Lightroom and Lightroom Mobile on my Ipad. On my desktop I have created a collection which I have put in a custom order. On my Ipad I go into that collection and set the order to custom order, which I presume means the order I have on my desktop. However, the photos on the Ipad seem to be just random photos from the collection THEN the rest of the collection is in the correct order after that.

    Do you have virtual copies in your collection?
    Could you please send send me a LR Desktop +Mobile diagnostig log  - best as a private message with a downloadable dropbox link
    You can trigger the Lr Desktop diagnostig log via LR Desktop preferences -> Lightroom Mobile and when you hold down the alt key you will notice a generate diagnostic log button.
    The Lr Mobile app log can be triggered when you open up the settings and long press the to LR Icon a diagnostic log will be generated and attached to your local mail client. While opening the settings could you double check if you are signed-in?
    Thanks
    Guido

  • Hi there! So I am using Lightroom 3 on a pc and I have ran into an issue when exporting images. The DPI and image size (in inches) that I am selecting during the export process. For example I just exported a collection and set the dpi to 180 and the size

    Hi there! So I am using Lightroom 3 on a pc and I have ran into an issue when exporting images. The DPI and image size (in inches) that I am selecting during the export process. For example I just exported a collection and set the dpi to 180 and the size to 7 inches on the long edge. My exported result is 457 dpi and sized at 3200x2134 pixels.. Any ideas on why this is happening and what I can do to correct it?

    The DPI setting in a digital image has no meaning at all. You need to learn how to calculate what you need in your exported image. The only measurement in a digital image that has any meaning is the number of pixels in each direction. It doesn't matter what you set that DPI to (actually it's PPI or pixels per inch). The image will have the same number of pixels regardless of the setting. If you need an image that is 5 x 7" (for example) at 200 PPI then you would want an image that measured:
    5 x 200 = 1000 pixels
    7 x 200 = 1400 pixels
    So you would need an image that is 1000 x 1400 pixels to have a 5 x 7" image at 200 PPI. The reason your exported image had such a high PPI setting is because you specified the number of inches you wanted the image to be. And there were enough pixels in the image that it calculated out to be that high PPI setting.
    I apologize, I don't explain this very well. But you need to learn to do the math to determine how large you really want your exported images to be.

  • Singleton class for logging in the application, and setting the flag

    Hi Friends,
    I have a singleton class for logging in the application, and setting the flag once logged. can some one help me in doing this.
    with regards,

    rtfm, for example here - http://www.javacamp.org/designPattern/

  • TS1372 my daughter took my ipod and set the volume limit and she put a code but dont know what she put and shes 2 years old ,can you help

    my daughter took my ipod and set the volume limit and she put a code but dont know what she put and shes 2 years old ,can you help

    You'll have to connect the iPod to your computer and restore it to factory settings in iTunes.  Then resync your music etc.

  • Having trouble getting Skype to work.  It did when I first got the computer about a yr ago but then quit.  I've trashed and reinstalled the program and set the preferences to allow Skype but nothing is working.  Any suggestions?

    Having trouble getting Skype to work.  It did when I first got the computer about a yr ago but then quit.  I've trashed and reinstalled the program and set the preferences to allow Skype but nothing is working.  Any suggestions?

    all I can suggest is completley unistall as here
    https://support.skype.com/en/faq/FA12073/how-can-i-completely-uninstall-and-then -reinstall-skype-for-mac-os-x
    Then reinstall
    http://www.skype.com/en/download-skype/skype-for-mac/

  • Why does my iPhone arbitrarily brighten, to the point of decreased resolution, despite my having turned off auto-brightness and setting the brightness to maximum?

    Why does my iPhone arbitrarily brighten, to the point of decreased resolution, despite my having turned off auto-brightness and setting the brightness to maximum?

    Could be a hardware failure.
    Restore the iPhone, first from a backup, then as new, and see if the issue persists. If it persists when you restore as new, then there's a hardware issue with your phone and you need to bring it to an Apple store to be evaluated.
    ~Lyssa

  • How to dump block and identify the bytes stored for each column

    SQL> select header_file, header_block
    2 from dba_segments
    3 where segment_name = 'APARTMENTS';
    HEADER_FIL HEADER_BLO
    4 1692
    1 row selected.
    SQL> alter system dump datafile 4 block 1693;
    Statement processed.
    How can I see the dump block and identify the bytes stored for each column?
    tab 0, row 0, @0x73b
    tl: 125 fb: H-FL lb: 0x1 cc: 4
    col 0: [25]
    52 65 64 77 6f 6f 64 20 53 68 6f 72 65 73 20 41 70 61 72 74 6d 65 6e 74 73
    col 1: [20] 00 54 00 01 02 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8d
    col 2: [53]
    00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 1b 8e 00 21 09 00 00
    00 00 00 00 11 00 00 00 00 00 01 45 6d 65 72 67 65 6e 63 79 20 44 65 74 61
    69 6c 73
    col 3: [20] 00 54 00 01 01 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8f

    SQL> select header_file, header_block
    2 from dba_segments
    3 where segment_name = 'APARTMENTS';
    HEADER_FIL HEADER_BLO
    4 1692
    1 row selected.
    SQL> alter system dump datafile 4 block 1693;
    Statement processed.
    How can I see the dump block and identify the bytes stored for each column?
    tab 0, row 0, @0x73b
    tl: 125 fb: H-FL lb: 0x1 cc: 4
    col 0: [25]
    52 65 64 77 6f 6f 64 20 53 68 6f 72 65 73 20 41 70 61 72 74 6d 65 6e 74 73
    col 1: [20] 00 54 00 01 02 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8d
    col 2: [53]
    00 54 00 01 02 0c 00 00 00 01 00 00 00 01 00 00 00 00 1b 8e 00 21 09 00 00
    00 00 00 00 11 00 00 00 00 00 01 45 6d 65 72 67 65 6e 63 79 20 44 65 74 61
    69 6c 73
    col 3: [20] 00 54 00 01 01 08 00 00 00 01 00 00 00 01 00 00 00 00 1b 8f

Maybe you are looking for

  • SSL VPN Login failure issue

    Hello, I am having an issue with some users trying to login to our SSL VPN (Anyconnect) via ASA5505 8.2(1).  Authentication is done via AD.  From the same computer, the client finds the DNS name and unlocks the login username and password.  When I en

  • Interactive Report questions

    Good Afternoon, I converted a sql classic report to an interactive report. The classic report has parameters, that once selected fires a page process that inserts data into a table, which creates column headings for my report. The parameters still wo

  • Why can't I download more than 3 movies on my i-pad

    I-tunes won't let me download more than 3 movies in my file.  I have converted my movies into H264 format which play great on the i-pad, but it won't let me download more than 3 movies.. Not sure why

  • App server 8.1 could not start

    Encounter App server 8.1 could not start Reason by bugger : Port Conflict Incorrect server config. Corrupt depoly app. Anyone could make to varify the actual cause. I using MS XP SP2, Norton Interent security and connect to internet while depoly to r

  • Toplink insert sequence

    Hi all: Is there any sequence in which toplink fires insert/update queries to the database if there is no object mapping..? Actually I have domain classes which have mapping using the primaryKeys but not the actual objects. I am using toplink 9037. R