Using RIGHT MAX CHARINDEX to get value

declare @lotTech varchar(64)
declare @lontNum varchar(64)SELECT @lotTech = RIGHT(MAX(l.lotID),CHARINDEX(' ','TECH'))
FROM lots l
if (@lotTech = '')
SET @lotNum = 'TECH 1';
else
SET @lotNum = 'TECH' + SPACE(1) + @lotTech + 1;
Can't get this to find if there is a null value or max value and 1 to concatnated data? 

@productID as bigint,
@lotNum as varchar(64),
@manufactureDate as datetime,
@expirationDate as datetime = null,
@gradeDesc as varchar(64)
as
BEGIN
declare @lotcheck varchar(64)
declare @lotTech varchar(64)
SELECT @lotcheck = lotid FROM Lots WHERE lotid = @lotNum
if (@expirationDate is null)
begin
SELECT @expirationDate = dateadd(day, ch.expiration, @manufactureDate)
FROM products p
INNER JOIN chemicals ch on p.chemicalID = ch.chemicalID
WHERE p.productID = @productID
end
if (@gradeDesc = 'TECH GRADE')
begin
SELECT @lotTech = RIGHT(MAX(l.lotID),CHARINDEX(' ','TECH'))
FROM lots l
if (@lotTech = '')
SET @lotNum = 'TECH 1';
else
SET @lotNum = 'TECH' + SPACE(1) + @lotTech + 1;
end
if (@lotcheck is null)
begin
INSERT INTO Lots(lotID, chemicalID, expirationDate, manufactureDate, confirmed, productID)
SELECT @lotNum as lotID, p.chemicalID, @expirationDate as expirationDate, @manufactureDate as manufactureDate, 0 as confirmed, p.productID
FROM products p
INNER JOIN chemicals ch on p.chemicalID = ch.chemicalID
WHERE p.productID = @productID
end
else
begin
UPDATE Lots
SET manufactureDate = @manufactureDate,
expirationDate = @expirationDate,
productID = @productID
WHERE lotID = @lotNum
end
return
END
I'm showing more of the TSQL which works fine but the part I'm not understanding is the use of essentially parsing the data that is TECH and the number which has to be the maximum number for TECH.
The output should be an ascending value concatnated with the word 'TECH' and a space.  Initially there is nothing in the lotNum column.  I need to get the MAX number out of the lots table for the paticular grade descripton -  'TECH GRADE'
and then add 1 to that retrived number for the insert of the record. 
So the first record to be inserted after the MAX number is found to be not present is
TECH 1
Following queries have to find the MAX number in the whole table and then add 1  and insert when 'TECH GRADE' description so
TECH 2
TECH 3

Similar Messages

  • How to use Spry.Utils.extractParamsFromForm to get value of a form element

    Can we use Spry.Utils.extractParamsFromForm to get value of a
    form element ?
    I tried this
    quote:
    var cid =
    Spry.Utils.extractParamsFromForm('adForm','category');
    Here the form name is adForm and category is an select item.
    This gives me error
    quote:
    elements.join is not a function
    Any idea on this guys.

    Can we use Spry.Utils.extractParamsFromForm to get value of a
    form element ?
    I tried this
    quote:
    var cid =
    Spry.Utils.extractParamsFromForm('adForm','category');
    Here the form name is adForm and category is an select item.
    This gives me error
    quote:
    elements.join is not a function
    Any idea on this guys.

  • Variable used in FOx formula should get value from user

    Hi Gurus,
    In my fox formula I want to multiply a keyfigure (say quantity) with a factor. For example if the factor is 10 then all records should get multiplied by 10.
    But the requirement is user shpuld be able to give the factor that should be multiplied. That is the l_factor used in the fox function should be a variable which gets value from user. I know we can give variables in filter and planning functions in IP. But can we give values in Fox formula.
    I would really appreciate the time and effort.
    Thanking you,
    Jerry Jerome

    Hello,
    May be you can try this solution.
    I think you have create a dummy character info-object(Z_Number) of same data type interget number.Create variable for Z_Number and restrict in filter(ZV_NUM).
    DATA Z_MAT TYPE 0Material.
    DATA Z_NUM TYPE Z_NUMBER.
    DATA Z_NUM_READ TYPE I.(Declate same as data type for Z_Number)
    Z_NUM = VARV(ZV_NUM).
    FORACH Z_MAT.
    Z_NUM_READ = Z_NUM.
    {Z_KF1,Z_MAT} = Z_NUM_READ * {Z_KF1,Z_MAT}.
    ENDFOR.

  • How to get value of a elementId in a form

    Hello
    In a form, I can use a name for a input field or checkbox
    <input type="text" name=studentName" />
    then I can use:
    request.getParameter("studentName") to get value of that name when the form is summitted.
    Now I want to use id instead of name.
    <input type="text" name="studentName" id ="name" />
    Can I get the value of this id "name" in the request ???
    Thank you
    shoa

    Hi,
    Rather not, because "parameters are contained in query string or posted in form data" (from javadoc). And how data is posted you can read in http://www.w3.org/TR/html4/interact/forms.html#control-name.
    Regards,
    Stefan

  • Using bean.variable for inputText but not getting value

    Hi I am using ADF BC JSF 10.1.3.2.
    I have a search page that has : dropdown1,
    based on dropdown1, I populate the dropdown 2 and with autosubmit and partialtrigger and also set either of the two search layouts true
    LAyout 1 based on dropdown1 value, say x, is rendered and I have 3 inputText , each have value= #{backingbean.variable}.
    Now when i am running this page, I got dropdown2 rendered with correct values and layout 2 rendered as required. Problem starts when I enter a value in the inputText1 and click on search button. In the search method, I try to get value for variable with so many ways : getVariable(), this.getInputText1.getValue()/// All these returned null.
    I tried to initialize the variable. In this case, the inputText1 showed initialised value and when i change value and submit, in the search method I still get the old initialised value.
    The inputText1 somehow never sets the value
    Please help..
    Regards
    Sudha

    Hi,
    I'm not exactly sure about what your functionality is but from what I gather the problem could be that if the bean is request scope then the value of the input text is already lost when you are trying to retrieve it.
    In any case I think that the best thing to do is to use the default view criteria functionality to perform the search if it is done on a view object.
    Gabriel.

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to get values from a table(in jsp) for validation using javascript.

    hi,
    this is praveen,pls tell me the procedure to get values from a table(in jsp) for validation using javascript.
    thank you in advance.

    Yes i did try the same ..
    BEGIN
    select PROD_tYPE into :P185_OFF_CITY from
    magcrm_setup where atype = 'CITY' ;
    :p185_OFF_CITY := 'XXX';
    insert into mtest values ('inside foolter');
    END;
    When i checked the mtest table it shos me the row inserted...
    inside foolter .. Now this means everything did get execute properly
    But still the vallue of off_city is null or emtpy...
    i check the filed and still its empty..
    while mtest had those records..seems like some process is cleaining the values...but cant see such process...
    a bit confused..here..I tried on Load after footer...
    tried chaning the squence number of process ..but still it doesnt help
    some how the session variables gets changed...and it is changed to empty
    Edited by: pauljohny on Jan 3, 2012 2:01 AM
    Edited by: pauljohny on Jan 3, 2012 2:03 AM

  • Using bean to get value

    This is what happens in my website
    index.jsp -> gets value from user and sends it to
    NewServlet.java -> after processing value redirects to result.jsp
    result.jsp - declares result from servlet
    I am doing this because my .jsp page contains a lot of extra code which I do not want to put it up in servlet. Apart from using regular code such as this in my result.jsp
    <jsp:useBean id="result" class="dna.DnaToRna" />
    <jsp:getProperty name="result" property="error" />is there any other way I can do this?

    Could you please show me some tutorial? Because I dont know how to do this?
    Did you mean using url?
    many thanks for replying.

  • How to get cm:search to use the max attribute when creating the SQL query?

    When we use the max attribute in the cm:search tag, it does not seem to honor the max attribute when creating the SQL query. However, the result returned from the tag is limited to the number specified by the max attribute. Then the tag seems to work as intended, but the performance will be sub optimal when the SQL query returns unnecessary rows to the application.
    We use the cm:search tag to list the latest news (ordered by date), and with the current implementation we have to expect a decrease in performance over time as more news is published. But we can’t live with that. We need to do the constraint in the SQL query, not in the application.
    The sortBy attribute of cm:search is translated to “order by” in the SQL query, as expected.
    Is it possible to get cm:search to generate the SQL query with an addition of “where rownum <= maxRows”?

    Hi Erik,
    The behavior of a repository in regards to the search tag's max results parameter is dependent on the underlying repository's implementation. That said, the OOTB repository in WLP does augment the generated SQL to limit the number of rows returned from the database. This is done in the parsing logic. This behavior may differ with other repository implementations.
    -Ryan

  • Unable to get values within scope of the RowGroup(only got values using Previous and current scope value)

    Hi All,
    I already calculated a row(Add Total row) like  Gross profit within Group1 (a,b,c,d,e which are sub groups) using Previous and current scope column group values. ex: Gross Profit = a - b. (within group1)
    Gross Profit = Previous(Sum(Fields!Trans_amount.Value)) - Sum(Fields!Trans_amount.Value) in Group1
    Now, I want to get values for Net income like  Net income = a - b - c in Group1.  (OR)
    Net income = Gross  Profit - c in Group1 (Using Gross Profit textbox values using Reportitems!textbox.value). but, values different.  Since Expression got new calculation)
     Please help me.
    Thanks Advance.
    - Prem Kumar T D http://www.sharepointbasic.com/

    Hi Premtd,
    As per my understanding, there are group and subgroups in the report, you added total to a group with the expresson: Previous(Sum(Fields!Trans_amount.Value)) - Sum(Fields!Trans_amount.Value). You want to add a text box to the report to calculate Net income
    with the expression: Previous(Sum(Fields!Trans_amount.Value)) - Sum(Fields!Trans_amount.Value) - Sum(Fields!Trans_amount.Value). In order to improve the efficiency of troubleshooting, I need to ask several questions:
    • “I already calculated a row(Add Total row) like  Gross profit within Group1 (a,b,c,d,e which are sub groups)” What’s the meaning of Group1 and subgroup a, b, c, d, e ? Could you please mark Gross profit and the groups in the screenshot?
    • How to calculate Net income? Please provide some more detailed information of your requirements. I would be appreciated it if you could provide sample data and clear screenshot of the report.
    This may be a lot of information to ask for at one time. However, by collecting this information now, it will help us move more quickly toward a solution.
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu

  • Help comparing the value of a button using the Property Node (I get a variant)

    Dear Sirs:
    (I'm using LabView 6. I guess the solution is different for 6.1)
    Currently I have created an array of Boolean RefNums (which point to many, many buttons). When I need to know when any (and which) of the buttons was pressed I just compare every element on the array with the constant TRUE. It fact, as the array is built from RefNums, I should compare the VALUE from the Property Node.
    The problem here is that the Property Node for this type of Boolean is a LV Variant, and I need to compare this with a TRUE/FALSE value.
    I tried to convert the TRUE constant to a LV variant and visc. But nothing works... I always get that none of the buttons was pressed.
    Here it co
    mes the question: "How can I compare the value of a Property Node for a Boolean (Button) with a TRUE (or False) constant?"
    BTW, maybe I should explain why I'm using RefNums instead of the direct values: As my project requires tons of buttons, I would preffer using RefNums to refer to them. (I.E. I could use a single VI that takes the RefNum and formats the button to hide it for certain users).
    I have enclosed a VI that contains what I've achieved until now, which is nothing
    I appreciate your time and help.
    Best regards,
    JAVIER VIDAL
    Attachments:
    Other_Main_Menu.vi ‏103 KB

    Javier,
    There is another problem in your code: the booleans are not polled by the main loop so they will remain false until the user presses them again. This renders the boolean latch action useless.
    What you can do is to change the mechanical action of the booleans to non-latch. When you detect a "true" in the polling loop, set the boolean to false again. One added benefit is that once all boolean are non-latch, the value property won't be a variant but a boolean so conversion is no longer needed.
    LabVIEW, C'est LabVIEW

  • With an reg size I pad using facebook. how do I get to see the chat coloumn on the right side of facebook page?

    with an I pad 4 using facebook, how do I get the chat coloumn on the  right side of facebook page to appear?

    Rotating the iPad into landscape orientation works for me.

  • CAN NOT write text on some webpages like googlemail if use right mouse click, last copied text gets pasted in against my will Macbook pro: OSX 10.6.8 Firefox,

    I would like to use right mouse click for spelling translate but when I click it pastes the last copied text in instead of opening the menu it happens on many webpages.
    thanks for help
    Elkan

    still having same problems.
    is this the only way to get support from firefox? where are the developers that write the code? or someone directly responsible for the product? i don't expect an end user to help but this is ridiculous. the windows version works fine but the mac version doesn't. i'm running both on the same machine so it's not the hardware (running windows as a virtual guest in parallels).

  • I can't launch Safari. When I right click on the icon, the "Application not responding" is grey and no matter what method I use to Force quit, I get no response.

    I can't launch Safari. When I right click on the icon, the "Application not responding" is grey and no matter what method I use to Force quit, I get no response.

    Do a backup.
    Quit the application.
    Go to Finder and select your user/home folder. With that Finder window as the front window, either select Finder/View/Show View options or go command - J.  When the View options opens, check ’Show Library Folder’. That should make your user library folder visible in your user/home folder.  Select Library. Then go to Preferences/com.apple.Safari.plist. Move the .plist to your desktop.
    Restart the computer, open the application and test. If it works okay, delete the plist from the desktop.
    If the application is the same, return the .plist to where you got it from, overwriting the newer one.
    Thanks to leonie for some information contained in this.

  • I don't have my phone anymore and need to get access to my contact list. Is there a way to get into my backed up info from the PC I'm using right now?

    I don't have my phone anymore and need to get access to my contact list. Is there a way to get into my backed up info from the PC I'm using right now?

    You can use another iPhone (or iPad) to restore it too, or you can login to www.icloud.com (assumng you weer using iCloud) and export your contacts from there.

Maybe you are looking for