Using Variables in Syntax

We are in the process of consolidating all data.  We have consolidated all our timekeeping/payroll data, but unfortunately the bulk of sale data still exists in tables based off store numbers.  I am needing to get a list of all employees who worked
on Black Friday (Nov 28) and take a look at their sales.  I took this in a two step approach one, get a list of all employees who had a clockin date of 11/28/2014 and insert them into a table, then step 2 I was going to iterate each employee from that
table and insert sale #'s into a second table, and query the final results of the 2nd table to show full circle.  Problem, I keep getting an error of 'Invalid Column Name 'Employee''  
Below is my syntax...speed is critical for me, so if there is a faster way of achieving these same results please let me know.  SQL Server 2008 is the server I am running this on.
Create Table #EmployeesWhoWorked (ID Int Identity, storeNum int)
Create Table #Results (empName, StoreNum int, empitemSold int, emptotalSold int)
--This works
Insert Into @EmployeesWhoWorked (storeNum)
Select storeNum
From timekeeping
Where clockindate = '11/28/2014'
--This is the piece that errors
Declare @N int, @Str Nvarchar(4000), @storeNum varchar(1000), @MaxID int)
Set @N = 1
Select @MaxID = Max(ID)
FROM #EmployeesWhoWorked
While (@N<=@MaxID)
Begin
Select @storeNum = storeNum
FROM #EmployesWhoWorked
Where ID = @N
Set @Str =
' Insert Into #Results (empName, StoreNum, empitemSold, emptotalSold)
Select empName, '+@StoreNum+', Count(itemSold), SUM(itemvalues)
From '+@StoreNum+'
WHERE clockindate = '11/28/2014'
Exec SP_ExecuteSQL @Str
Set @N = @N + 1
End
Select *
FROM #Results

E.g.
CREATE TABLE #EmployeesWhoWorked
ID INT IDENTITY ,
storeNum INT
CREATE TABLE #Results
empName VARCHAR(1000) ,
StoreNum INT ,
empitemSold INT ,
emptotalSold INT
DECLARE @clockindate DATE = '20141128';
INSERT INTO #EmployeesWhoWorked
( storeNum
SELECT storeNum
FROM timekeeping
WHERE clockindate = @clockindate;
DECLARE @N INT ,
@Str VARCHAR(MAX) ,
@storeNum INT ,
@MaxID INT;
SET @N = 1;
SELECT @MaxID = MAX(ID)
FROM #EmployeesWhoWorked;
DECLARE @SQL VARCHAR(MAX);
SET @SQL = '
INSERT INTO #Results
( empName ,
StoreNum ,
empitemSold ,
emptotalSold
SELECT empName ,
@storeNum ,
Count(itemSold) ,
SUM(itemvalues)
FROM @TableName
WHERE clockindate = @clockindate;
WHILE ( @N <= @MaxID )
BEGIN
SELECT @storeNum = storeNum
FROM #EmployesWhoWorked
WHERE ID = @N;
SET @Str = REPLACE(@SQL, '@TableName', QUOTENAME(CAST(@storeNum AS VARCHAR(255))));
EXEC sp_executesql @Str, '@storeNum INT, @clockindate DATE', @storeNum, @clockindate;
SET @N = @N + 1;
END;
SELECT *
FROM #Results;
But I don't understand your loop approach..

Similar Messages

  • Syntax to export 18 months of data at any given time using variables?

    I have written a calculation script for exporting data from an application using DATAEXPORT. I want to get 18 months of data in my exported text files at any point of time. So, I want to specify the range using variables for Period and Year but I am kind of stuck on how should I be writing it in my script.
    Please let me know the correct syntax using variables or if you could share some link that would help me know that would be a help.
    Can I use @XRANGE Function???
    Thanks !

    Srinivas --> Thanks for clarifying that. After I read your post I did go through the @XRANGE again and noticed that they had use cross dimensional operators so it put me in a confusion. But you cleared it by being more specific this time. Thanks a lot !
    If I follow what Robb suggested then like you mentioned when 3 years will be involved its going to be difficult I guess. Not sure at this point which way would be the best to get this work.
    I agree with CL - 18 months rolling forecast can be annoying seriously.
    Can one of you please suggest me a permanent and most efficient solution for this out of all the ideas that would not require manual work and can be automated completely?
    Thank you all for your inputs. I really appreciate it.
    Edited by: 892254 on Nov 3, 2011 6:30 AM

  • Using variables in the title of the graph

    Hi Gurus,
    I would like to use - for example a presentation- variable in the title of a graph.
    I assign a value for that variable in dashboard prompt.
    Does anybody know the syntax of using variable in the title of a graph
    (Not in a Title view!)
    Thanks in advance .
    Regards
    Laszlo

    You can reference presentation variables in the following areas :
    Title Views
    Narrative Views
    Column Filters
    Column Formulas
    Conditional Formatting conditions
    Chart scale markers.
    Gauge range settings.
    Static text.
    Direct Database Requests
    Dashboard prompts
    iBot Headlines and text

  • How can I use variable name as a prameter value in HOST Command ???

    Hi All,
    How can it possible to use variable value in parameter in HOST command ??
    Following in my code:
    host('rwclient server=reptest report=c:\cust_print.rdf p_1= s_sam_cust_id userid=wh1/wh1@dwh desformat=pdf desty=file desname=c:/temp/'||v_sam_cust_id||'.pdf');
    Regards

    Hello,
    The Syntax of the builtin HOST is :
    SyntaxPROCEDURE HOST
    (system_command_string VARCHAR2);
    PROCEDURE HOST
    (system_command_string VARCHAR2,
    screen_action NUMBER);
    So , you can build the system_command_string as any VARCHAR2
    Example are provided in online help :
    http://www.oracle.com/webapps/online-help/forms/10g/topics/f1_help/builth_m/host.html?tp=true
    Regards

  • Using @variable('BOLanguage') prompts in webi documents

    Hello,
    I am using @variable('BOLanguage') in the universe to handle multilinguism.
    Unfortunately, when running my webi document, the variable prompts whereas it is a BO variable.
    On top of that, let us suppose, I enter "test" as a value for this variable, when it is evaluated, the variable is evaluated as 'fr' or 'en' but not as 'test' which proves that this variable should not prompt.
    Does anyone have any idea about how to prevent 'BOLanguage' from prompting.
    Thanks in Advanced
    Sylvie

    Oh, ok that's interesting. I went back to find the documentation but couldn't find anything specific to BOLANGUAGE, just to @Variable in the Universe designers guide.
    http://help.sap.com/businessobject/product_guides/boexir31SP2/en/xi31_sp2_designer_en.pdf
    It mentions entering -var parameter at the command line when starting BO to get access to other variables, and the syntax to use for @variable. It also mentions language variables like 'Preferred Viewing Locale', but nothing about 'BOLanguage'. Anyway, looks like you have answered your own question.
    Thanks

  • Using variable/s in SOM expression... how?

    Hello all,
    Sometimes its the simplest things that are the most confusing (for me anyway). For example:
    I have a static table in a form in which the cells in one column each contain a checkbox.
    The reference for each checkbox would be:
    Table1.Row1.ckbox[0]
    Table2.Row2.ckbox[0]
    Table3.Row3.ckbox[0]
    and so on.
    I have a button elsewhere on the form, which when clicked would set each of the checkboxes in the table to "1" or checked, and would uncheck them all when clicked again.So I'm thinking a simple for loop would do the trick.
    var i
    for i = 1 upto 12 do
         Table1.Row[i].ckbox = 1
    endfor
                   ---OR---
    for (var row = 1; row < 13; row++)
        form1.main.front.Table1.Row" + row + ".CheckBox = 1;
    Neither works.
    Is it the syntax, or something else entirely? Any pointers to examples of how and when to use variables in SOM references would be extremely appreciated.
    Thanks
    Harry Ohm.

    Hi Harry,
    You need to resolve the node in Javascript, so the following should work:
    for (var i=1; i< 13; i++)
        xfa.resolveNode("form1.main.front.Table1.Row" + i + ".ckbox).rawValue = 1;
    The way you have stated the name of the checkbox "Table1.Row1.ckbox[0]", indicates that there may be more than one ckbox in each row. If that is the case then you may need to replace .ckbox in the script with .ckbox[0].
    Hope that helps,
    Niall
    Assure Dynamics

  • [DW 8.02 + PHP] how to use variables in advanced SQL queries

    Hi all,
    I can't find a way to use variables in an SQL query after
    updating
    dreamweaver 8.02.
    I always get error messages that says: 'missing variable
    type:myvariablename', undefined#myvariablename... and so on.
    What is the correct way to use variables?
    I usually set a variable in a PHP statement (example: <?
    $today=date('Y-m-d'); ?>)
    and then I compare this variable in the SQL query.
    What is the correct syntax for variable in DW 8.02 in
    advanced SQL
    queries?
    TIA
    tony

    sweetman wrote:
    > I'm editing a website created with DW 8.01 and MX
    Kollection.
    >
    > I updated DW to 8.02 and now I can't edit an existing
    SQL query.
    > I always get an error message 'Missing variable type'
    and I can't go
    > on.
    InterAKT released a new version of Kollection to cope with
    the 8.0.2
    changes. AFAIK, you should be able to download the updated
    version from
    your InterAKT account area.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Using Variables in a "Report Custom Functions"

    Hi!
    I created a custom function using Basic Syntax where I am trying to declare/use variables.  I keep getting syntax errors and don't know why.  Here is my code so far:
    Function cdQSIPeriod () As String
    YY = Year(CurrentDate)
    MM = Month(CurrentDate)
    If MM = 1 then
        MM = 12
        YY = YY - 1
    else
        MM = MM - 1
    cdQSIPeriod = String(MM)& String(YY)
    End Function
    Any help you can provide will be appreciated.

    You need to add
    dim YY as number
    dim MM as number
    HTH,
    Carl

  • Use variables in ParallePeriod function in MDX

    Hello, I am using PARALLELPERIOD () function in MDX. the syntax is
    PARALLELPERIOD([Date].[Calendar Hierarchy].[Year],1,[Date].[Calendar Hierarchy].[Date].&[20131201]). My question is can i use two variables in this? like PARALLELPERIOD( @Level,1,@Member). I know we can do PARALLELPERIOD([Date].[Calendar Hierarchy].[Year],1,@Member).
    With this two variables, i can use same query for calendar hierarchy and week hierarchy etc. Please let me know your thoughts. A work around solution is also fine.
    or can I derive @level from @member on the fly? something like PARALLELPERIOD( @Member.level,1,@Member)
    thanks in advance.
    prajwal kumar potula

    You can use variables like that client side.  That may be a .NET function that generates MDX, or SSRS does the same thing.
    Regarding whether you can derive @Level from @Member, yes you can.  Once you have substituted @Member in the query, you can use the .Level function, so it would look like this - after substitution:
    PARALLELPERIOD( [Date].[Calendar Hierarchy].[Date].&[20131201].Level,
    1,
    [Date].[Calendar Hierarchy].[Date].&[20131201]
    Christian Wade
    http://christianwade.wordpress.com/
    Please mark correct responses as answers!

  • Use variable in mapping

    Hi!
    How to use Variable in mapping ? I've tried #PROJECT_CODE.VARIABLE_NAME but execution ends with an error "Illegal character"
    With regards,
    PsmakR

    There is no need to use package name if variable is locate in the same package with the interace. Else (according with documentation):
    Referring to variable MY_VAR in your objects should be done as follows:
    • #MY_VAR: With this syntax, the variable must be in the same project as the object referring to it. Its value will be substituted. To avoid ambiguity, consider using fully qualified syntax by prefixing the variable name with the project code.
    • #MY_PROJECT_CODE.MY_VAR: Using this syntax allows you to use variables across projects. It prevents ambiguity when 2 variables in different projects have the same name. The value of the variable will be substituted at runtime.
    • #GLOBAL.MY_VAR: This syntax allows you to refer to a global variable. Its value will be substituted in your code. Refer to section Global Objects for details.
    • Using “:” instead of “#”: You can use the variable as a SQL bind variable by prefixing it with a colon rather than a hash. However this syntax is subject to restrictions as it only applies to SQL DML statements.
    And make sure you declare it in the package as was suggested in the previous post.

  • Personalisation - 'Launch a Function' using variables as parameters

    I am trying to call a function from another form using Built In 'Lanch a function'.
    In Add parameters, If I provide hardcoded values, its working fine. When I try to pass variables such as :GLOBAL.XX_ITEM_ID or ${item.folder.item_id.value} ,
    it errors out
    When I use GLOBAL variable, the error is 'Type does not match definition in form XXX ' I tried using to_char , to_number but no use.
    When I use item.folder.item_id.value it errors out with 'FROM keyword not found'
    I tried putting them in single quotes, pipes etc.
    Can anybody tell me how to pass variabes while launching a function?
    Thanks a lot.

    I just solved it. Used the following syntax
    'G_QUERY_FIND=PO_LINE_LOCATION_ID
    PO_LINE_LOCATION_ID='||${global.xx_po_line_location_id.value}

  • Invoking a service using BLOB data syntax

    Hi All,
    When invoking LC using BLOB the syntax is:
    //Create a BLOB object
    BLOB inDoc = new BLOB();
    //Populate the BLOB objects remoteURL data member
    inDoc.remoteURL = urlData;
    //Invoke the EncryptDocument process
    BLOB outDoc = encryptClient.invoke(inDoc);
    How the syntax goes when my service has also an input string variable,
    and how to handle the result if it also returns output string
    variable?
    Thanks in advance!

    Hi Jasmin,<br /><br />I've copied this code from "Invocation API quick starts" document,<br />see the full code:<br /><br />import com.adobe.idp.services.*;<br />import java.io.File;<br />import java.io.FileOutputStream;<br />import java.io.InputStream;<br />import java.net.URL;<br />import javax.activation.DataHandler;<br />import javax.activation.FileDataSource;<br />import org.apache.axis.attachments.AttachmentPart;<br />public class InvokeDocumentEncryptDime {<br />public static void main(String[] args) {<br />try{<br />//create a service locator<br />EncryptDocumentServiceLocator locate = new<br />EncryptDocumentServiceLocator();<br />  //specify the service target URL and object type<br />URL serviceURL = new<br />URL("http://localhost:8080/soap/services/EncryptDocument?blob=dime");<br />//Use the binding stub with the locator<br />EncryptDocumentSoapBindingStub encryptionClientStub = new<br />EncryptDocumentSoapBindingStub(serviceURL,locate);<br />encryptionClientStub.setUsername("administrator");<br />encryptionClientStub.setPassword("password");<br />//Get the DIME Attachments - which is the PDF document to encrypt<br />java.io.File file = new java.io.File("C:\\Adobe\\Loan.pdf");<br />//Create a DataHandler object<br />DataHandler buildFile = new DataHandler(new FileDataSource(file));<br />//Use the DataHandler object to create an AttachmentPart object<br />AttachmentPart part = new AttachmentPart(buildFile);<br />//get the attachment ID<br />String attachmentID = part.getContentId();<br />//Add the attachment to the encryption service stub<br />encryptionClientStub.addAttachment(part);<br />//Inform ES where the attachment is stored by providing the attachment id<br />BLOB inDoc = new BLOB();<br />inDoc.setAttachmentID(attachmentID);<br />BLOB outDoc = encryptionClientStub.invoke(inDoc);<br />//Go through the returned attachments and get the encrypted PDF document<br />byte[] resultByte = null;<br />attachmentID = outDoc.getAttachmentID();<br />//Find the proper attachment<br />Object[] parts = encryptionClientStub.getAttachments();<br />for (int i=0;i<parts.length;i++){<br />AttachmentPart attPart = (AttachmentPart) parts[i];<br />if (attPart.getContentId().equals(attachmentID)) {<br />//DataHandler<br />buildFile = attPart.getDataHandler();<br />InputStream stream = buildFile.getInputStream();<br />byte[] pdfStream = new byte[stream.available()];<br />stream.read(pdfStream);<br />//Create a File object<br />File outFile = new File("C:\\Adobe\\EncryptLoan.pdf");<br />//Create a FileOutputStream object.<br />FileOutputStream myFileW = new FileOutputStream(outFile);<br />//Call the FileOutputStream objects write method and pass the pdf<br />data<br />myFileW.write(pdfStream);<br />//Close the FileOutputStream object<br />myFileW.close();}}}<br /><br />The process I wish to invoke has 2 input parameters:<br />string variable  and a document,also this process returns a string and document as output.<br /><br />Do you have any example how to invoke it and handle its result?<br /><br />Thanks!

  • Using variables w/ loadMovieNum

    what is the proper syntax for using variables with loadMovie
    num?
    ive set up a button that will define a var
    on (press) {
    var bigpic = "2";
    _root.gotoAndPlay("out");
    and then further down the timeline ,
    i would like to use that the var bigpic in a loadMovieNum
    command....
    but what is the proper way to do this ?
    thanks,
    tony

    it all depends on what the intention of the variable bigpic
    is... is it intended as the level you want to load a movie in? if
    so then it needs to be a number rather than a string:
    var bigpic = 2;
    and then later:
    loadMovieNum("pic.jpg", bigpic);
    but maybe bigpic is the number of the picture that you want
    to bring in...?
    then you use something like:
    loadMovieNum("pic"+bigpic+".jpg", 2);
    (assuming that you're bringing in jpgs, that they're called
    pic1.jpg, pic2.jpg etc and you're loading them into level 2.)
    See
    documentation

  • Use ansi join syntax

    From what i have been reading is better to use the new syntax(dont know how new it is)

    The ANSI join syntax was new to Oracle in Oracle 8i in 1998 - that's 15 years old.
    It can produce more readable code, and is both more readable and less human-error prone for outer joins.
    The ANSI format lets you outer join between multiple tables in a way the old oracle-specific ( + ) syntax did not and introduces FULL OUTER JOIN which you should use very rarely.
    You should not use NATURAL JOIN in code - adding unrelated columns to the tables involved can make it give very different results.
    There have not been significant bugs for ANSI joins in Oracle since Oracle 10.2 was introduced about 8 years ago.
    As Paul said, the ON part should be the join criteria between the tables. The were clause should be the filtering of the joined tables.
    So assuming start_date, end_date and in_property_id are variables
    SELECT resv_num, unit_date
        FROM p_resv_unit ru
        INNER JOIN p_pm_unit_night pun
        ON pun.resv_unit_id = ru.resv_unit_id
        WHERE pun.property_id = in_property_id
        AND pun.unit_date BETWEEN start_date AND end_date
        AND pun.pm_unit_num = cvUnitNum;
    If start_date and end_date were columns in p_resv_unit the query would be:
    SELECT resv_num, unit_date
        FROM p_resv_unit ru
        INNER JOIN p_pm_unit_night pun
        ON pun.resv_unit_id = ru.resv_unit_id AND pun.unit_date BETWEEN ru.start_date AND ru.end_date
        WHERE pun.property_id = in_property_id
            AND pun.pm_unit_num = cvUnitNum;
    Inner join queries work with criteria in the wrong place, but they're harder to read. Outer joins don't work unless you put the criteria in the right place.

  • Error-Receiver File Adapter using Variable substitution when file is empty

    XI Experts,
    We are on PI 7.0, SP14.
    We are using variable subtitution to get the filename from source message. This works fine as long as we have data in the payload for filename element. But we have a scenario where we don't have to create file when certain condition does not exists in source message so in the message payload filename element will not exists in such condition and file will be empty and we should not create file.
    Parameter in the communication channel for Handling empty message is "Ignore".
    Does anyone knows how to handle this scneario. We don't want to default any file name in the message mapping if source file name element does not exists.
    We are following getting error in the Adapter engine.
    MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Error during variable substitution: com.sap.aii.adapter.file.varsubst.VariableDataSourceException: The following variable was not found in the message payload: file: com.sap.aii.adapter.file.configuration.DynamicConfigurationException: Error during variable substitution: com.sap.aii.adapter.file.varsubst.VariableDataSourceException: The following variable was not found in the message payload: file
    Thanks
    MP

    You can implement this by writing the module to throw an exception or whatever method you want to execute.
    If you don't want to receive an error message then module is suitable for you.
    Gaurav Jain

Maybe you are looking for

  • Touch Screen unresponsive after iOS 8 update

    My 1 year old 64GB iPhone 5 touch screen started to become unresponsive after iOS 8 update It's not consistent. Touch screen functionality will seize whilst phone is being used for either answering calls, typing messges, surfing, gaming etc and won't

  • HT1689 Changing Apple ID for a family member.

    i have been sharing my iTunes with my wife. if I create new Apple ID for her will she loose data, apps, iCloud ets.

  • HT201272 I rented a movie from iTunes but Movist is not playing it. It says " Movist quit unexpectedly" What should I do?

    Hi, Just an hour ago I rented "Brave" from İtunes Turkey. After download has been finalized, I wanted to watch it. Unfortnately Movist says that "Movist quit unexpectedly". So I download another movist from app store and I paid also for it but this o

  • Updating JTable From Database

    Hi, I am new to Swing and I was wondering if anyone could help me with the following problem. I have a tablemodel which extends AbstractTableModel which is used to create my JTable. The data to display in the table is got from a SELECT statement from

  • Exicse Duty in trading

    Hi,           Can anybody help me to map these scenario....... Scenario:- Dealer purchases excisable goods, his item cost includes excise duty as he is not claiming any credits, when he make sale of these items he only collect Vat. Requirements is he