Remove last 3 caracters in a view

Hi Guys,
I'm creating a view, in a specific colomn there are 3 values that i want to cut off. The original table can't be changed because of ETL issues.
Here's what i tried:
SELECT
, Left(COLOMN1, LEN (COLOMN1) - 3)
,COLUMN2
,COLUMN3
FROM TABLE1
The query goes for a while and then gives me the error:
Msg 537, Level 16, State 2, Line 4
Invalid length parameter passed to the LEFT or SUBSTRING function.
The values in the colomn have various lenghts. I also need the other colomns in that table.. Hope anyone's got a sollution

Your query fails for records where then length of colomn1 is less then 3; the calculation returns a negative value =>
SELECT
,CASE WHEN LEN(COLOMN1) <= 3 OR COLOMN1 IS NULL THEN COLOMN1 ELSE Left(COLOMN1, LEN (COLOMN1) - 3) END
,COLUMN2
,COLUMN3
FROM TABLE1
Olaf Helper
[ Blog] [ Xing] [ MVP]

Similar Messages

  • Best way to remove last line-feed in text file

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)
    According to my experiments, you have removed all line terminators from the file, and replaced those between lines with a space.
    That is to say, you have turned a multi-line file into one long line with no line terminator.
    If that is what you want, and your files are not very big, then your echo statement might be all you need.
    If you need to deal with larger files, you could try using the 'tr' command, and something like
    tr '
    ' ' ' <file.txt >newfile.txt
    The only problem with this is, it will most likely give you a trailing space, as the last newline is going to be converted to a space. If that is not acceptable, then something else will have to be arranged.
    However, if you really want to maintain a multi-line file, but remove just the very last line terminator, that gets a bit more complicated. This might work for you:
    perl -ne '
    chomp;
    print "
    " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    You can use cat -e to see which lines have newlines, and you should see that the last line does not have a newline, but all the others still do.
    I guess if you really did mean to remove all newline characters and replace them with a space, except for the last line, then a modification of the above perl script would do that:
    perl -ne '
    chomp;
    print " " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    Am I even close to understanding what you are asking for?

  • When I open a new tab, the new tab used to show shots of 6 or so of the last sites I'd viewed, so I could easily click on one and go to it. Now it shows a blank tab and I have to type the URL of the page I want. How can I change it back?

    When I open a new tab, the new tab used to show shots of 6 or so of the last sites I'd viewed, so I could easily click on one and go to it. Now it shows a blank tab and I have to type the URL of the page I want. How can I change it back?

    Did you have the Google Toolbar installed?
    * http://www.google.com/support/toolbar/bin/answer.py?answer=115561 Web-browsing tools : Google new tab page and most visited websites
    Other extension that have a similar feature:
    *Speed Dial: https://addons.mozilla.org/firefox/addon/4810
    *Fast Dial: https://addons.mozilla.org/firefox/addon/5721

  • Opening a pdf file automatically opens last 13 pdf files viewed

    I use Adobe Acrobat a lot and for some reason, I opened a pdf document yesterday and the last 13 files I viewed automatically opened.  I rebooted my computer and it still does the same thing.
    Does anyone know how to switch off this automation?
    Appreciate anyone's feedback.
    Sincerely,
    dd1atslb

    Do a Get Info on one of the PDF files - select the file (click it once), then press Command-I (Get Info in the File menu).
    In the Get Info window, about half-way down is an item "Open with:" - set the pulldown menu in that section to "Preview".
    If you want to make that change to all PDFs, then click the "Change All..." button.

  • Removing live nodes from cluster view.

    Hi All,
              We are experiencing some JMS problems connected with a cluster node being
              hung for some time.
              The following took place just before the problem arises:
              1. First of all one of the nodes (the first) gets one thread
              (weblogic.jms.backend.BEPushRequestSender@76512c) stuck.
              2. After that it closes the TCP connection to another node and
              3. Removes another node from its cluster view.(that is alive)
              4. After that the second node removes the first from its cluster
              view.
              5. Seconds later they find each other again and add each other to the
              cluster view.
              6. After that, the JMS distributed members are connected to each other,
              7. Something strange happens, because either the first node starts
              missing many messages in its distributed topic member or the second
              node doesn't propagate messages from distributed topic to the first
              node.
              Is it possible to set up weblogic cluster in a way, it won't remove
              other members from cluster view by peer gone exception, only by
              heartbeat timeout? Is heartbeat retry time parameter is configurable?
              Any help with this matter will be greatly appreciated.
              Dmitry Finkelstein
              

    You must run the update node list for each ORACLE_HOME on that machine. If this is RAC, the runInstaller will take care to update all nodes, so again, you run it once per ORACLE_HOME installed.
    Shared Home is a single copy of the Oracle software, rather than each node holding their own copy of the software. There's a paper that talks about these two topics and gives some examples of full commands on OTN:
    http://www.oracle.com/technology/products/database/clustering/index.html
    "Oracle Homes in an Oracle Real Application Clusters Environment(PDF) January 2008"
    direct link: http://www.oracle.com/technology/products/database/clustering/pdf/oh_rac.pdf
    Enjoy and hope this helps.
    Saar.

  • How can I save my photos on a removable hard drive for easy viewing?

    I just got a brand new Macbook Pro and I wanted to transfer some of the photos from my old computer over to my new computer (from a My Passport removable hard drive), but I found that this wasn't possible with how I had saved then with iPhoto.  I now have all of my photos on my new computer, but don't want to waste all that space.  How can I save the photos I don't want on this computer to my removable hard drive for easy viewing?  When I look at the removable hard drive now, it's saved altogether as iPhoto Library, so I can't just see certain ones...

    While in iphoto,hold down the command key and select all the pics you want to move. Once all the pics are selected, release the command key and select export from the file menu. Iphoto will present a dialog box where you can select the quality of the pics before exporting. Then export them to whereever you would like. If you want to put them on an external HD then select that.When you wish to view them,you can use preview or right click on any pic and choose which program to open them with.After doing this if you no longer want them in iphoto then delete them and make sure to empty the trash in iphoto after doing so.

  • How do I remove a url from "Always view this page in IE"

    How do I remove a URL from "Always view this page in IE"?

    After the new server is added to the cluster and the AG, remove the old one by first
    ALTER AVAILABILITY GROUP [YourAG]
    REMOVE REPLICA ON N'OldServer';
    Remove a Secondary Replica from an Availability Group
    Then evict the old server from the cluster with the cluster administrator or
    Remove-ClusterNode OldServer
    Remember to verify the quorum configuration after adding the new server and removing the old server.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • Remove last selection for parameters

    Hello expert,
    I have a webi report with multiple parameter inherited from store procedure on which universe is built up. how can I remove last select variant for all parameters ? I mean for every running, I want to select parameters from scratch. but currently in my report, parameters display last selection.
    Many Thanks,

    Hello,
    I believe if you go into the universe and right click on the stored procedure, it should give you an edit option. Then you should be able to select the parameter and change it to "Prompt for a value" or something like that. There are probably some other posts regarding how to do this. I am not sure I have it all correct since I don't have BO up right now, but pretty sure I have done it before.
    Thanks

  • Remove Last part

    i have this data
    ELECT  [item_id]  ,[f2] from [Regions]
    1. ُEgypt
    1.1. Cairo
    1.1.21. New Cairo
    i want to remove last part 
    like in Egypt remove 1.
    and on Cairo remove  last 1.
    and on New Cairo last 21.

    Try:
    DECLARE @City TABLE ( CityName varchar(100));
    INSERT @City VALUES
    ('1. Egypt'),
    ('1.1. Cairo'),
    ('1.1.21. New Cairo'),
    ('1.1.21.5. Alexandria')
    -- SELECT STUFF('abcdef', 2, 3, 'ijklmn');
    SELECT
    CityName, RenumberedCityName=
    LTRIM(STUFF(REVERSE(SUBSTRING(SUBSTRING(REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)+1,LEN(CityName))+'.',
    CHARINDEX('.',SUBSTRING(REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)+1,LEN(CityName))+'.'),len(CityName))),1,1,'')+SPACE(1)+
    REVERSE(LTRIM(RTRIM(LEFT (REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)-1)))))
    FROM @City WHERE CHARINDEX('.',CityName) > 0;
    CityName RenumberedCityName
    1. Egypt Egypt
    1.1. Cairo 1. Cairo
    1.1.21. New Cairo 1.1. New Cairo
    1.1.21.5. Alexandria 1.1.21. Alexandria
    -- USING hierarchyid method
    SELECT
    CityName, RenumberedCityName=
    LTRIM(REPLACE(STUFF(CONVERT(hierarchyid,'/'+REPLACE(LEFT(CityName, CHARINDEX(' ', CityName)-1),'.','/')).GetAncestor(1).ToString(),1,1,''),'/','.')
    +SPACE(1)+REVERSE(LTRIM(RTRIM(LEFT (REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)-1)))))
    FROM @City WHERE CHARINDEX('.',CityName) > 0;
    CityName RenumberedCityName
    1. Egypt Egypt
    1.1. Cairo 1. Cairo
    1.1.21. New Cairo 1.1. New Cairo
    1.1.21.5. Alexandria 1.1.21. Alexandria
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Remove last 4 digits

    Hi all,
    I want to remove last 4 digits from my numerical no. how can i do this?
    Plz help me.

    hi
    good
    w_level_03 = strlen( W_STRING ).
    lv_offset = w_level_03 - 4.
    w_string2 = w_string +(lv_offset).
    or
    w_string2 = w_string +0(lv_offset).
    Eg:-
    str = "testing1234".
    int offset = strlen( str ) - 4.
    str = str+0(offset).
    thanks
    mrutyun^

  • Remove last 3 char ..

    Hi ,
         I need to remove last 3 char from my varible which is char 30.
    For example : WERKS = 1000 and .
    I need to remove last 3 char (and) from the above varibale .Kindly guide this
    Regards,
    VC

    Hi veerachamy,
    Just copy this code..it will work fine even if the field changes dynamically..
    I took w_char as 30 char..u can give ur field name there...
    data:
    w_char(30) type c value 'asdfghjklpoiu',
    w_tmp(30) type c,
    w_tmp1 type i.
    w_tmp1 = strlen( w_char ).
    w_tmp1 = w_tmp1 - 3.
    w_tmp = w_char+0(w_tmp1).
    write: w_tmp.
    Hope it resolves the issue...
    Regards
    Kiran

  • HT2513 After accepting the new Apple upgrade to iOS 7.1 on my iPhone 4S, I cannot remove the half month calendar view to show only the daily view. Help!

    After accepting the new Apple upgrade to iOS 7.1 on my iPhone 4S, I cannot remove the half month calendar view to show only the daily view. Help!

    Before you panic, try resetting your iPhone by simultaneously pressing and holding the Home and Sleep/Wake buttons until you see the Apple Logo. This can take up to 15 seconds so be patient and don't release the buttons until the logo appears.
    Try again to see if the problem persists.

  • FCP5 removes last frame from any 23.98fps movie

    I'm having an issue with 23.98fps Quicktimes in FCP. When I play the clip in Quicktime, the frame count is correct. When the same movie is opened in the FCP viewer or dropped in a bin, FCP removes the last frame. For example, say I have 2 clips, identical in every way except for frame rate:
    Clip A - 720p Photo-JPEG 120 frames 24fps
    Clip B - 720p Photo-JPEG 120 frames 23.98fps
    In QT7, both clips play correctly, contain all frames, and are reported in the info window to be 5 seconds exactly. In FCP Clip A, plays correctly, contains all frames, and has a reported length of 00:00:05:00. Clip B is missing the last frame and has a reported length of 00:00:04:23.
    I have done this same test with a 480 frame clip as well with the same results. QT7 reports 20 seconds, FCP reports 00:00:19:23.
    I have had this problem with quicktime movies from different sources as well, not just QT movies I have created. It is imperative that I find out what is causing this issue. If anyone can offer any suggestions/answers at all, it would be much appreciated.
    PowerMac Dual G5   Mac OS X (10.4)  

    hello anthony.
    i can't offer any explanation, but i can offer what might be a work around. i am assuming you need to work at 23.98 and that you are receiving exact frame count files.
    if you receive files @ 24fps which are correct, try using cinema tools to "conform" these files to 23.98 ... just open the file from within cinema tools and hit the conform button. i'd be interested to know if these conformed files maintain the correct frame count.
    a guess might be that the export or transcode process might be the source of the error.
    R.

  • Bulk remove last action stop

    Hi,
    I have around 3000 fla files that I need to remove the last action stop in their actionscript.
    I have meanwhile found no way to do this. Any ideas?
    Much apprecaited!

    Thank you both for your replys...
    I have a software that enables people to add animations to IM softwares. In this case, the flash is sent to the recepient and run once.
    Now we are building a directory for the animations online and it makes sense that when browsing an animation, the animation will loop and not stop after 1 view.
    Any help would be greatly apprecaited as it will save me weeks of work
    thanks!

  • How to replace or remove last 500 bytes of a file without rewriting all the file?

    Hi everyone,
    Usually I only ask for help when I can't find a solution for several days or weeks... And guess what? That just happen!
    So, this is what i am trying to do:
    I have a program to ZIP folder and protect them with password, then it encrypts the zip file.
    That it's working fine, until the user forgets his password.
    So, what I want to do is give the user a Recovery Password option for each ZIP file created. I can't use the Windows Registry because the idea is to be able to recover the password in any computer.So i came up with an idea...
    In simple terms, this will work like this:
    0 - Choose folder to ZIP
    1 - Ask user for recover details (date of birth, email etc)
    2 - ZIP folder with password
    3 - Encrypt ZIP file
    4 - Encrypt recover details and convert it to HEX
    5 - Add recover details (in HEX) to the end of the ZIP file (last bytes)
    6 - Add "5265636F76657244657461696C73" which is the text "RecoverDetails" in HEX
    7 - Add "504B0506000000000000000000000000000000000000" this is the final bytes of a ZIP file and will make the Operating System think that is a ZIP file (i know that will give an error when we try to open it.. the ideia is to change the
    extension later and use my software to do all the work to access this ZIP/folder again)
    So, explaining what it's here, I want to say that I managed how to do all of this so far. The point number 6 will help us to determine where the recover details are in the file, or if they actually exist because user can choose not to use them.
    In order to unlock this ZIP and extract it's contents, I need to reverse what I've done. That means, that  need to read only the last 500 bytes (or less if the file is smaller) of the ZIP and remove those extra bytes I added so the program can check
    if the user is inputing a correct password, and if so decrypt contents and extract them.
    But, if the user insert a wrong password I need to re-add those bytes with the recover details again to the ZIP file.
    The second thing is, if the user forgets his password and asks to recover it, a form will be shown asking to insert the recover detail (date of birth, email etc), so we need to reed the last 500 bytes of the ZIP, find the bytes in number 6 and remove the
    bytes before number 6, remove bytes in number 6 and number 7, and we will have the recover details to match against the user details input.
    I have all done so far with the locking process. But i need help with the unlocking.
    I am not sure if it's possible, but this what i am looking for:
    Read last 500 bytes of a file, remove the bytes with recover details and save the file. Without reading the whole file, because if we have a 1GB file that will take a very long time. Also, i don't want to "waste" hard drive space creating a new
    clone file with 1GB and then delete the original.
    And then add them back "in case user fails the password" which should be exactly the same.
    This sounds a bit confusing I know, even to me, I am writing and trying to explain this the better I can.. Also my English is not the best..
    Here it goes some code to better understanding:
    'READ LAST 500 BYTES OF ZIP FILE TO CHECK IF IT CONTAINS RECOVER DETAILS
    Dim oFileStream As New FileStream(TextBox_ZIP_to_Protect.Text & ".zip", FileMode.Open, FileAccess.Read)
    Dim oBinaryReader As New BinaryReader(oFileStream)
    Dim lBytes As Long = oFileStream.Length
    oBinaryReader.BaseStream.Position = lBytes - 500
    Dim fileData As Byte() = oBinaryReader.ReadBytes(500)
    oBinaryReader.Close()
    oFileStream.Close()
    Dim txtTemp As New System.Text.StringBuilder()
    For Each myByte As Byte In fileData
    txtTemp.Append(myByte.ToString("X2"))
    Next
    Dim RecoveryDetailsPass_Holder = txtTemp.ToString()
    'Dim Temp_2 = txtTemp.ToString()
    'RichTextBox1.Text = txtTemp.ToString()
    If txtTemp.ToString.Contains("505245434F47414653") Then
    'we have password recovery details(the numbers mean RecoverDetails in HEX)
    'next we will get rid of everything before and after of string "cut_at"
    Dim mystr As String = RecoveryDetailsPass_Holder 'RichTextBox1.Text
    Dim cut_at As String = "505245434F47414653"
    Dim x As Integer = InStr(mystr, cut_at)
    ' Dim string_before As String = mystr.Substring(0, x - 1)
    Dim string_after As String = mystr.Substring(x + cut_at.Length - 1)
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace(string_after.ToString, "")
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace("505245434F47414653", "") ' this is RecoverDetails in HEX
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace("504B0506000000000000000000000000000000000000", "") ' this is the bytes of an empty zip file
    'AT THIS POINT WE HAVE ONLY THE RECOVER PASSWORD DETAILS (date of birth, email etc) IN THE VARIABLE "RecoveryDetailsPass_Holder"
    '////////////////////////////////////////////////////// TO DEBUG
    'MsgBox(string_after.ToString & "505245434F47414653")
    'InputBox("", "", string_after.ToString)
    '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ TO DEBUG
    'Temp_2 = Temp_2.Replace(RecoveryDetailsPass_Holder.ToString, "")
    Now that we have the recover details, we need to remove them from ZIP in order to the software try to unzip it with the password provided by the user on the GUI.
    If the user needs to recover the password we have the details already in RecoveryDetailsPass_Holder variable and just need to match them against user input details.
    If the user fails, we need to put the RecoveryDetailsPass_Holder back on the file.
    Any question just ask, it's a bit trick to explain i think, but please ask.
    Anyone know how to do this?
    Many thanks in advanced.
    Nothing is impossible!
    @ Portugal
    Vote if it's helpfull :)

    @ ALL
    Thank you very much for you help. I know that if I'm "playing" with bytes you should assume that I know a lot of VB.net, but I don't know that much unfortunately. I am not a beginner but I am still very fresh and I probably do stuff that work but
    probably not in the best way...
    Anyway, I will explain the idea of this little software I'm making. Once I wanted to create a program to protect folders with password, and I came up with something to change folder permissions to lock access to them, and that actually worked fine and quickly.
    However, I managed how to "crack" the protection by going to folder properties, security tab and then give permissions back to my username. So that, to me, wasn't a safer system to protect folders, also I want the ability to use passwords. So I search
    and search online for a way to do it, and someone replied (to someone with the same question as me) that the best option would be to create a zip with all contents of the folder, with password and then change the extension from .zip to .whatever and register
    the new extension .whatever on the Windows Registry, so that file will have an icon and open with my software.
    So I did...The program zips everything, change the extension and I added the encryption to avoid people changing the extension to ZIP or trying to open with 7-Zip or similar and be able to see the protected files names in the .zip/.whatever
    Answering to all of you now:
    @Armi
    "System.IO.FileStream.SetLength"
    I know I tried that but I erased the code because it didn't work for some reason, I don't remember why sorry, was long time before I created this post.
    The last code I was trying to use was this:
    ' Set the stream position to the desired location of the stream.
    Dim fileStream As IO.FileStream = _
    New IO.FileStream(TextBox_ZIP_to_Protect.Text & ".zip", IO.FileMode.Append)
    Try
    ' Set the stream (OFFSET) position to the desired location of the stream.
    fileStream.Seek(210, IO.SeekOrigin.Current)
    Dim Bytes_do_ZE As Byte() = HexStringToByteArray(Temp_2.ToString)
    'Write Characters ASCII
    For Each Byte_Do_Zeca As Byte In Bytes_do_ZE
    fileStream.WriteByte(Byte_Do_Zeca)
    Next
    Finally
    fileStream.Close()
    End Try
    and we need this:
    Private Shared Function HexStringToByteArray(ByRef strInput As String) As Byte()
    Dim length As Integer
    Dim bOutput As Byte()
    Dim c(1) As Integer
    length = strInput.Length / 2
    ReDim bOutput(length - 1)
    For i As Integer = 0 To (length - 1)
    For j As Integer = 0 To 1
    c(j) = Asc(strInput.Chars(i * 2 + j))
    If ((c(j) >= Asc("0")) And (c(j) <= Asc("9"))) Then
    c(j) = c(j) - Asc("0")
    ElseIf ((c(j) >= Asc("A")) And (c(j) <= Asc("F"))) Then
    c(j) = c(j) - Asc("A") + &HA
    ElseIf ((c(j) >= Asc("a")) And (c(j) <= Asc("f"))) Then
    c(j) = c(j) - Asc("a") + &HA
    End If
    Next j
    bOutput(i) = (c(0) * &H10 + c(1))
    Next i
    Return (bOutput)
    End Function
    That code, as I understand, is to search for the OFFSET of the bytes in the file and start to write from there... That OFFSET should be the beginning of the 500 bytes read on the code before. I got the OFFSET position "210" reading the file with
    the HEX editor "HxD - Hexeditor v1.7.7.0" but using the OFFSET won't work because every file, password, recover details and so on, are different and so the file size, changing the OFFSET I
    think.
    @Reed Kimble
    Does that sound like something which might work for you?
    Thanks for your help. That might be some solution, however it seams a bit of the same problem where we need to read the bytes again to get the recover details. But, as I said in this post, because this is meant to password protect folders, do you think that
    will apply as well?
    @Crazypennie
    Thanks for your reply.
    All this appears really weak. The user has your application since he need it to open the file .... and the code in the application contain the code to read the file without knowing the password. Therefore anyone can read your code and retrieve the
    data without the password ... if he knows VB.
    The application can only open the file if the user didn't use a password to protect the file. Because the file is encrypted and needs to be unencrypted first.
    When the application tries to open/read the file, will need to decrypt it first and then check for a password and do the validation. Also the application is with the code masked/protected which i think it might not be easy for reverse engineering.
    - You need to use a web server and a symmetric key encryption
    This a good idea, besides I don't know how to implement it. However the idea is to be able to:
    1 - Protect a folder anywhere in any Windows computer (portable app)
    2 - Recover password details (security question) in any computer, online and offline
    And I think we need a computer always connected to the Internet to use that method, right?
    @ Mr. Monkeyboy
    Thank you very much for your effort.
    I just wanted to let you know that the zip method you are using is no longer supported.
    I didn't actually knew that. Thanks for letting me know.
    Do you require the compressed encrypted files to actually be Zip files or could they just be compressed files that have nothing to do with Zip?
    No, it doesn't need to be a .zip extension. I am actually using my own extension. It starts as a Zip but then I changed to my own extension which I have registered on the Windows Registry.
    @ ALL
    Thanks again to all for trying and spending time helping me.
    By the way, I might not be able to answer or try any code during the weekend... It's easter break and family is around. Have a nice easter everyone. :)
    Nothing is impossible! Imagination is the limit!

Maybe you are looking for