Script or Dababase Query

Hello,
I'm not sure how I'd accomplish the following. I appreciate any assistance you can give.
When column NewRevRequired = Yes; I need to get the last revision code in desc order and afterwards increment to the next higher code.
When column NewRevRequired = No; I need to get the last revisioncode in desc order.
Below is a sampling of the code.
When NewRevRequired = Yes
   ** Get the last revision in desc order and increment by one.
   Select TOP 1 RevRevision
     case RevReVision
        when 'A' then 'B'
        when 'B' then 'C'
        when 'C' then 'D'
     end 
   FROM DOCUMENTRECORDS_67
   where RevProductCode = '#PartProdCode#'
   ORDER BY RevRevision desc
ELSE
When NewRevRequired = No
   ** Get the last revision in desc order.
   Select TOP 1 RevRevision
   FROM DOCUMENTRECORDS_67
   where RevProductCode = '#PartProdCode#'
   ORDER BY RevRevision desc

Also, a variant on Jingyang's answer, combining the OP's original Case statement nested within the case statement.  Jingyang's is more robust, but this demonstrates nesting one CASE within another. 
create table DOCUMENTRECORDS_67 (did int primary key,NewRevRequired varchar(3), RevProductCode varchar(50), RevRevision char(1))
Insert into DOCUMENTRECORDS_67 values
(1,'Yes','#PartProdCode#','A'),
(2,'Yes','#PartProdCode#','B'),
(3,'Yes','#PartProdCode#','C'),
(4,'No','#PartProdCode#','A'),
(5,'No','#PartProdCode#','B'),
(6,'No','#PartProdCode#','C')
Select did
, CASE WHEN NewRevRequired='Yes' Then
CASE RevRevision
WHEN 'A' then 'B'
WHEN 'B' then 'C'
WHEN 'C' then 'D'
END
Else RevRevision
End as RevReVision
FROM DOCUMENTRECORDS_67
where RevProductCode = '#PartProdCode#'
ORDER BY NewRevRequired, RevRevision desc
drop table DOCUMENTRECORDS_67

Similar Messages

  • Can I query to PowerShell scripts from Power Query ?

    Can I query to PowerShell scripts from Power Query ?
    I want to use PowerShell result for Data Visualization in Excel.
    Like importing from web, odata, hdinsight, etc,
    I want to import result of PowerShell script.
    PowerShell can do a lot of system management.
    Regards,
    Yoshihiro Kawabata 

    This is not possible today and is not something that's likely to be implemented. The combination of being able to easily share queries and being able to easily launch external scripts that can do anything supported by the current user's permissions is
    something of a security nightmare.

  • Using Powershell Script Run simple query in MS Access 2007 and export the results of query to Excel

    Hi Experts,
    I have a Access 2007 DB file and 2 Big tables inside that (bigger than the size that can be easily handled by MS Excel 2007).
    My requirement is automate using powershell scripts the below things.
    1. Create a SQL query in Access DB and save that in access DB
    2. Run the saved query and export the result in excel sheet where I can create the charts and Pivots. Thanks in advance
    Prajesh

    Do you have to use the Access query, couldn't you just recreate the query in Powershell?  Here's a link with good info that references an existing script for querying an Access database:
    http://blogs.technet.com/b/heyscriptingguy/archive/2009/08/13/hey-scripting-guy-can-i-query-a-microsoft-access-database-with-a-windows-powershell-script.aspx
    Once you have your dataset you can pipe it to
    Export-Csv -NoType c:\pathtofile\output.csv

  • A script that will query for the last successful backup to tape across all protected datasources

    I've searched trying to locate an existing script for this and come up empty so far but essentially what I am trying to do is have a script I can run that will query for the latest backup to tape that succeeded for each data source across all of the protection
    groups then output that time/date for each to a file.
    I'm extremely new to scripting so I am unsure of how to go about getting started with this so any help would be greatly appreciated!

    this should work
    foreach ($DS in $DSList)
    $RP=$DS | Get-RecoveryPoint | where {$_.Location -eq "Media"} | Sort-Object -Property Backuptime -Descending | select -First 1 | select *
    $Tape=Get-DPMTape -DPMLibrary $Library | where {$_.ID -eq $Rp.RecoverySourceLocations.MediaMapList.MediaId}
    $obj = New-Object -TypeName PSObject
    $obj | Add-Member Noteproperty -Name DatasourceName -value $DS.Name
    $obj | Add-Member Noteproperty -Name Sourcecomputer -value $DS.Computer
    $obj | Add-Member Noteproperty -Name BackupTime -value $RP.BackupTime
    #$obj | Add-Member Noteproperty -Name Location -value $Tape.Location.tostring()
    #$obj | Add-Member Noteproperty -Name Medialabel -value $Tape.Medialabel
    #$obj | Add-Member Noteproperty -Name Barcode -value $Tape.Barcode.Value
    $Array+=$obj
    Seidl Michael | http://www.techguy.at | twitter.com/techguyat |
    facebook.com/techguyat |
    youtube.com/techguyat

  • Ho to get script result with query's in 11g

    Hi,
    While doing refresh tasks i need to run some select query's. am so lazy to check each query one by one so i placed all querys in one script and i ran
    i went fine but it is showing only result of the query but it is not showing query. Can we get query and out put of query through script.
    Ex : one.sql
    the script have below querys
    select name from v$database;
    select count(*) from v$datafile;
    select count(*) from dba_db_links;
    select owner,db_link from dba_db_links;
    can any one help me on this..
    Regards
    Edited by: 889571 on May 19, 2013 2:59 PM

    [oracle@localhost samples]$ cat sample.sql
    set term on echo on
    select name from v$database;
    select count(*) from v$datafile;
    select count(*) from dba_db_links;
    select owner,db_link from dba_db_links;
    [oracle@localhost samples]$ sqlplus user1/user1 @sample.sql
    SQL*Plus: Release 11.2.0.2.0 Production on Sun May 19 16:06:20 2013
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select name from v$database;
    NAME
    ORCL
    SQL> select count(*) from v$datafile;
      COUNT(*)
             6
    SQL> select count(*) from dba_db_links;
      COUNT(*)
             0
    SQL> select owner,db_link from dba_db_links;
    no rows selected
    SQL>

  • Script needed to query last logon for users within an AD security group

    Hi all,
    I'm looking for a vbscript that will query a specific AD security group, and export the following information into an Excel document:
    1. Full name of the user.
    2. A timestamp of the last logon for each user.
    Any help would be great.

    At the moment I'm using a batch script to attempt to query a few different security groups. Below is a line from the script:
    dsquery group -samid <group name> | dsquery * -filter "&(objectClass=person)(ObjectCategory=user)" -attr cn lastLogonTimestamp
    There a two issues with the command.
    1. The results aren't being pulled from the security group specified.
    2. The timestamp is in an unreadable format. I've understand this needs to be converted?
    The Powershell option looks handy, but sadly the clients environment is Server 2003 based with no Powershell option.

  • PowerShell Script: How to query a current logon user in part of E.G AD group domain1\Group1 ?

    Hi Scripts guys,
    I am new to powershell . I would like to achieve the following :
    1. to check e.g if current logon user is member of .e.g. to domain1\group1
    if yes then execute another
    a. do a subst of a: to d:
    b. follow by executing the 2nd cmd e.g execute.ps1  
    else exit and
    proceed with execute.ps1
    please advice how best to achieve this ? Thanks in advance for your help :)

    When testing the "current user" for group memberships, I prefer to do it locally using the user's logon token rather than having to query the directory. This has the advantage of automatically dealing with nested group memberships, and working
    with local / builtin groups as well. Something along these lines:
    function Test-CurrentUserIsMember
    [CmdletBinding()]
    param (
    [Parameter(Mandatory = $true)]
    $Group
    $sid = $Group -as [System.Security.Principal.SecurityIdentifier]
    if ($null -eq $sid)
    $account = $Group
    if ($account -isnot [System.Security.Principal.IdentityReference])
    $account = [System.Security.Principal.NTAccount][string]$Group
    try
    $sid = $account.Translate([System.Security.Principal.SecurityIdentifier])
    catch
    throw "Group '$Group' could not be resolved to a Security Identifier"
    return ([System.Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains $sid)
    if (Test-CurrentUserIsMember -Group 'DOMAIN1\Group1')
    # User is a member of the group (directly, or via nested group memberships.)
    Write-Host "Is Member"
    else
    # User is not a member of the group.
    Write-Host "Is Not Member"

  • How to check UNUSED ADMIN-SCRIPTS through SQL Query..??

    Can someone help me with the SQL query, which would give result of total unused ADMIN SCRIPTs for past few months?? (not the routing scripts)
    Thanks in advance for your help n concern..!!

    You can youse the below queries
    Step 1:
    Query to pull the used scripts between 17/12/2011 to 18/01/2012
    select MasterScriptID,EnterpriseName from Master_Script where MasterScriptID in (
    select MasterScriptID from Script where ScriptID in(
    select distinct(ScriptID) from Route_Call_Detail
    where DateTime between '2011-12-17 00:00:00' and '2012-01-18 23:59:59'))
    Step 2:
    Query to pull all the current configured Scripts 
    select MasterScriptID,EnterpriseName from Master_Script
    Step 3:
    Once we get both the data, we can use Excel’s VLOOKUP functionality to find the unused Scripts
    Regards,
    Senthil

  • ASO Calc Script (AKA Saved Query)

    We leveraging query tracking and have attempted to leverage the saving of the tracked queries as script we should be able to run monthly... Should be able to is the problem..!!
    Our outline dimensions are static, but the structured are very fluid and this seems to keep our scripts from working. Does anyone have an idea how we can leverage these scripts, or something like. I have attempted to leverage the following process with limited success
    1. enable query tracking
    2. materialize suggested views
    3. run report scripts to mirror regular retrieval issues
    4. materialize the views based on the tracking
    Length process, but beats nothing..
    Any other idea's??

    I think you might be confusing BSO calc scripts with ASO custom calcs, there is a whole section in the documentation on ASO calcs - http://docs.oracle.com/cd/E40248_01/epm.1112/essbase_db/aso_custcalc_alloc.html
    There are also examples on the internet if you search spend some time researching.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Script VBS IP Query to determine office/site location

    Hi Guys,
    I'm in desperate need of a VBS that can query an ip address which will determine location.
    Example
    Bristol office 192.67.0.46
    Cardiff Office 192.67.2.40
    Newcastle 192.67.23.1
    So if a computers IP address falls within 192.67.0.1 - 192.67.0.255 we will know this device is in Bristol..
     If a computers IP address falls within 192.67.2.1 - 192.67.2.255 we will know this device is in Cardiff..
    Once location is identified tell the script to goto Cardiff/Bristol/Newcastle section of script.
    Hope this makes sense.
    O

    This is an End User forum for peer-to-peer discussions about the Windows 7 operating system.
    VBS discussions are address in the appropriate application development MSDN Community.  You can find the link @
    http://msdn.microsoft.com/en-us/library/t0aew7h6%28v=vs.84%29.aspx
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”

  • SQL script within my query

    I'm in dire need for some help. I'm creating a report in Oracle Reports Builder 10.1 and I'm having some issue with retrieving data with the script I wrote. The report I have is filitered by cont_type = 'SC'. One field that I am trying to get has a cont_type of something other then SC or it is NULL. That field is called revised amount. I want to be able to see the results for the revised amt field (revised_amt) even though i'm filitering them out. Is there a way to do that? The other part to it is that the revised amt field will need to be summarized and reset after each contract #. For example...
    Contract #_______Contract Amt_____Revised Amt
    1455-001-SC_____1,023,560.00
    1455-002________________________56,236.00
    1455-003________________________789,653.00
    1356-001-SC_____23,563,566.00
    1356-002________________________25,666.00
    1289-001-SC_____5,222,659.00
    1289-002________________________15,456.00
    1289-003________________________123,456.00
    So for the end result i would like to see the totals of the revised amount for each contract #. It would look something like this
    Contract #______Contract Amt______Revised Amt
    1455-001-SC_____1,023,560.00______845,889.00
    1356-001-SC_____23,563,566.00_____25,666.00
    1289-001-SC_____5,222,659.00______138,912.00
    I'm new to SQL so please be patient with me. Thanks!
    This is my SELECT statement below. Just to clarify, sccont_cont_code's format is 0033-0001. I have to concatenate the '9' onto the beginning of it because the cont_codes have a 9 in front. I apologize in advance for my limited knowledge of SQL and PL/SQL. I am in the process of learning it as we speak. I'm being put into a tough position in my current job and in order for me to succeed I must learn this valuable tool. I appreciate any help for yall and maybe a possible tip here and there. Thanks again!
    SELECT '9' || sccont_cont_code, NVL(sccont_cont_amt, '0.00'), fl2030_ven_bp_name, fl2030_job_code, fl2030_job_name, NVL(sccont_hldbk_amt, '0.00'), NVL(sccont_bill_amt, '0.00'), NVL(sccont_paid_amt, '0.00'), sccont_chg_amt
    FROM flpm2030_v
    ,sccont
    WHERE fl2030_job_code = sccont_job_code
    AND fl2030_comp_code = sccont_comp_code
    AND fl2030_chg_code = sccont_chg_code
    AND fl2030_ven_code = sccont_ven_code
    AND fl2030_comp_code != 'ZZ'
    AND fl2030_cont_type LIKE 'SC'
    ORDER BY fl2030_ven_bp_name
    Edited by: House on Jul 22, 2010 1:44 PM

    So for the end result i would like to see the totals of the revised amount for each contract #. It would look something like this
    Contract #______Contract Amt______Revised Amt
    1455-001-SC_____1,023,560.00______845,889.00
    1356-001-SC_____23,563,566.00_____25,666.00
    1289-001-SC_____5,222,659.00______138,912.00  Hello,
    If you looks for the above result, then you can try with below code
    SELECT SUBSTR(CONT_NO,1,4), SUM(CONT_AMT),SUM(REVS_AMT) FROM TBLCONTRACT
    GROUP BY SUBSTR(CONT_NO,1,4)and in order to get the main contract number, you can write a function in report, which will accept the first 4 digit of the contract number and return the concatenation string of -001-SC. Hence this function output you can use as the first column value
    If my post is helpful mark accordingly.
    Regards
    Manoj
    Edited by: ManojP on Jul 23, 2010 7:41 AM

  • SAP Script form Related Query

    Hello Everyone,
    I am a newbie to SAP Script.I have to find a way to display an alternative payee addrees on the cheque output, if specified in the vendor record rather than the actual vendor's address, Can any one please help me out here,Thanks.At the moment it is just printing the each line of the address as a separate fields from the REGUH table.

    Hi ,
                  You need to create a new Subroutine type program, with name which you will be giving in your PERFORM statement.
                   For that you write the PERFORM statement in IF and ENDIF statement.
    Ex:-
    /: IF &REGUH-LIFNR& EQ '   '.
    /: PERFORM ....
    code
    /:ENDPERFORM
    address fields of Alternate Payee
    /: ENDIF
    Regards
    Bala Krishna
    Edited by: Bala Krishna on Sep 5, 2008 1:23 PM

  • Script to query OU for last Windows update date and time

    Hi All, I need help in writing a script which can query an OU in active directory and then return most recent date of windows updates installation. It will also be helpful if the script can sort the names and then send output to a file (any format will
    do). I know basic of querying a local computer but not remote query, I am terrible at scripting side of powershell. Thanks people.

    I am referring to the script below, how can I get the result to output in an XLS or CSV format, I tried couple of combinations but couldn't get it to work.# This script shows the last time that a successfull Windows Update was installed.clsadd-PSSnapin quest.activeroles.admanagement 
    $OnlineServers = @() 
    Get-QADComputer -SearchRoot 'domain.com/ServerOU'-OSName "Windows*Server*"| %{ 
      $PingResult = Get-WmiObject-Query "SELECT * FROM win32_PingStatus WHERE address='$($_.Name)'"If ($PingResult.StatusCode -eq 0)  
         # Add the current name to the array$OnlineServers+= "$($_.Name)" 
    foreach ($Serverin$OnlineServers ) 
            $key = “SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install” 
            $keytype = [Microsoft.Win32.RegistryHive]::LocalMachine 
            $RemoteBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$Server) 
            $regKey = $RemoteBase.OpenSubKey($key) 
            $KeyValue = $regkey.GetValue(”LastSuccessTime”) 
            $System = (Get-Date-Format "yyyy-MM-dd hh:mm:ss")  
            if    ($KeyValue-lt $System) 
                Write-Host " " 
                Write-Host $Server"Last time updates were installed was: "$KeyValue
        }

  • SAP Query, SAP Script

    please give the step by step details . SAP Script and SAP Query .

    Hi Krishna,
    <b>SAP query</b>
    http://www.thespot4sap.com/Articles/SAP_ABAP_Queries_Introduction.asp
    https://www.sdn.sap.com/irj/sdn/advancedsearch?query=how%20to%20create%20sap%20query&cat=sdn_all
    <b>SAP Scripts</b>
    http://www.sap-img.com/sapscripts.htm
    http://sappoint.com/abap/
    http://www.henrikfrank.dk/abapexamples/SapScript/sapscript.htm
    http://help.sap.com/saphelp_crm40/helpdata/en/16/c832857cc111d686e0000086568e5f/content.htm
    http://www.sap-basis-abap.com/sapabap01.htm
    http://www.sap-img.com/sapscripts.htm
    http://searchsap.techtarget.com/tip/1,289483,sid21_gci943419,00.html
    http://sap.ittoolbox.com/topics/t.asp?t=303&p=452&h2=452&h1=303
    http://www.sapgenie.com/phpBB2/viewtopic.php?t=14007&sid=09eec5147a0dbeee1b5edd21af8ebc6a
    Regards
    Aneesh.
    ~~The best practice is to search the forum before posting a thread.

  • Need VB script or Batch file to query Dirty bit

    Hi Friends,
    Could anybody help me in setting up a script which can query Dirty bit on all volumes of 50 servers ?
    Thanks

    Mike / JRV,
    With your help, I could make a script which can find the local drives in a server. But i am blocked to proceed with dirty bit check on those local drives.
    Iam trying my level to find it out :)
    Thanks
    Arun
    You didn't look in the Repository did you?  You also didn't try the code posted above.  We cannot do this for you or would you like someone to remote into your system and do the typing?                     
    fsutil dirty query C:
    ¯\_(ツ)_/¯

Maybe you are looking for

  • Error in Info Package

    Hi Experts, Yes, i have one column 'unit' is blank. meaning no value in that column. how can i flag this error off? where shall i set? "Error in conversion exit CONVERSION_EXIT_CUNIT_INPUT" It seems i only have this error when i upload my file to the

  • Why is the iTunes Match setup process causing iTunes (and my machine) to freeze?

    I purchased iTunes Match several days ago, and it continues to freeze iTunes, subsequently locking up my machine. It keeps getting stuck on step 1 of the setup process (analyzing my library); I have left it overnight several times with no luck. At th

  • Trouble Burning

    IDVD is not letting me burn the movie on a DVD. This is what it tells me. "Errors were found during the burning process. The error #-1 was reported." What could cause this problem?

  • How to close the browser from an Applet?

    Hi, I've written one applet, with 2 buttons (Continue & Exit). On click of Continue button, it will open another web page. On click of Exit button, the browser should be closed. I'm not able to close the browser from the applet. Can any body help me.

  • Locking secondary display for slideshow.  Auto Export after tethered shooting?

    I use LR 3.5 when I shoot tethered.  It seems the upgrade to 3.5 helped with the inconsistent connection problem on my D3. I still get dropped but not as often. Thanks for working on that. I've been using LR for a photo booth arrangement.  I add logo