Creating static sql from dynamic sql

HI ,
I have a dynamic sql and  I have to convert it into a static sql .
this query is somehow having a special case which states that if the values of one parameter @bounce_type is D then it appends some more conditions(column conditions) on this query .
I want to know a way to convert this kind of SQL to a static sql .
I want a static code for the code where the condition is as mentioned below
for the where clause where @bounce_type='D'
if @bounce_type is not null and @bounce_type = 'D'
begin
print @bounce_type
set @WhereClause = @WhereClause + ' and per.event_type_id=4 and per.aspen_action_detail_id not in
(select
aspen_action_detail_id
from
program.email_response pers with (readuncommitted)
inner join action.action ac with(nolock,readuncommitted) on
pers.action_id = ac.action_id
where
pers.dealer_id in( ' + cast(@dealer_did as varchar(10)) + ' ) and
pers.aspen_action_dt between ''' + convert(varchar(10),@from_date,101)+''' ' + 'and ''' + convert(varchar(10),@to_date,101) + ''' and
pers.program_type_id in (4,5) and
pers.event_type_id=1 and
pers.is_enabled=1) and aa.program_group<>''Unknown'''
I was able to convert almost all of the code but the code mentioned above.

Perhaps this one
if @bounce_type is not null and @bounce_type = 'D' 
begin
print @bounce_type
SELECT * FROM tbl WHERE ... and per.event_type_id=4 and per.aspen_action_detail_id not in
(select
aspen_action_detail_id
from 
program.email_response pers with (readuncommitted)
inner join action.action ac with(nolock,readuncommitted) on
pers.action_id = ac.action_id  
where 
pers.dealer_id in(  cast(@dealer_did as varchar(10)))  and 
pers.aspen_action_dt between  convert(varchar(10),@from_date,101) and 
convert(varchar(10),@to_date,101)  and 
pers.program_type_id in (4,5)
and
pers.event_type_id=1
and
pers.is_enabled=1) and aa.program_group<>'Unknown' 
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • How to create Static menu and Dynamic menu..?

    Hi,
         I'm new to flash and Action Script, I need to add static menu and dynamic menu to my application. I'm using Action Script 1.0. Can you help me to solve my problem..?
    Regards,
    Appu

    Hi Adithya,
    I think the following article is a great resource :
    http://www.ibm.com/developerworks/library/os-eclipse-3.3menu /index.html
    The current documentation for popup menu could be found here :
    http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench_basicext_popupMenus.htm
    (it is also available locally if you install the Eclipse Platform SDK, in "Help" -> "Help Contents"-> "Platform Plug-in Developer guide")
    Best regards,
    Mariot
    adithya a écrit :
    > Hello,
    > Can anyone tell me as to how to create a 'Context Menu' (static and
    > dynamic)??
    > Also what is the difference between a static and dynamic context menus?
    >
    > Are there any javadocs or tutorials?
    > Please help.
    >
    > Adithya.
    >

  • How to Create file link from dynamic table.

    Howdy -
    I have MySQL database over PHP containing a simple table that lists a group of documents, including their file system address (contained within the site).
    I've successfully created a recordset showing this table, and attached that to a dynamic table on a .php page.  The display is correct, except I can't get the column contents to link to the document.  The column just shows the text (title) of the document.
    I've consulted article tn_15364 (http://kb2.adobe.com/cps/153/tn_15364.html), but that doesn't seem to work...
    Any thoughts would be appreciated.  I'm sure this is pretty simple, but I'm coming up snake eyes.
    Charles Andrews

    To clarify:
    My site has a folder where uploaded files (.doc, .xls, .pdf, etc.) are stored after having been uploaded by a user.  During this upload process, the location of these files is stored, along with other identifying data, in a simple database table.
    I have a dynamic table created in Dreamweaver that pulls from this database, listing the document name, etc. I would like the document name shown in a column to automatically link to the actual file so a user could just click on it and open the file.
    I hope I'm not making sound more complicated than it is -
    Thanks,
    CWA

  • Dynamic sql versus static sql in a loop

    I have a loop that loops around 10 million times.Inside the loop I have a insert statement . To build this insert statement wondering if a) I should use Dynamic sql using bind variables or b) static sql.
    I am aware that static sql is always faster than dynamic sql(using bind variable)....but wanted to get some opinion
    Please help.

    mmm some solution could be to write the same insert with decode/case statement and put there the conditions that you want.
    maybe something like this:
    SQL> ed
    Wrote file afiedt.buf
      1  begin
      2    for i in 1..10 loop
      3      insert into t1 (col1,col2,col3)
      4        values (i,
      5                decode (mod (i,2),0,i,null),
      6                decode (mod (i,3),0,i,null));
      7    end loop;
      8* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> select * from t1;
          COL1       COL2       COL3
             1
             2          2
             3                     3
             4          4
             5
             6          6          6
             7
             8          8
             9                     9
            10         10
    10 rows selected.
    SQL> truncate table t1;
    Table truncated.
    SQL> insert into t1 (col1,col2,col3)
      2    select rownum,
      3           decode (mod (rownum,2),0,rownum,null),
      4           decode (mod (rownum,3),0,rownum,null)
      5    from dual
      6  connect by rownum <=10;
    10 rows created.
    SQL> select * from t1;
          COL1       COL2       COL3
             1
             2          2
             3                     3
             4          4
             5
             6          6          6
             7
             8          8
             9                     9
            10         10
    10 rows selected.forgot that you are not using anymore the loop :)
    Message was edited by:
    Delfino Nunez

  • How to create a function with dynamic sql or any better way to achieve this?

            Hello,
            I have created below SQL query which works fine however when scalar function created ,it
            throws an error "Only functions and extended stored procedures can be executed from within a
            function.". In below code First cursor reads all client database names and second cursor
            reads client locations.
                      DECLARE @clientLocation nvarchar(100),@locationClientPath nvarchar(Max);
                      DECLARE @ItemID int;
                      SET @locationClientPath = char(0);
                      SET @ItemID = 67480;
       --building dynamic sql to replace database name at runtime
             DECLARE @strSQL nvarchar(Max);
             DECLARE @DatabaseName nvarchar(100);
             DECLARE @localClientPath nvarchar(MAX) ;
                      Declare databaselist_cursor Cursor for select [DBName] from [DataBase].[dbo].
                      [tblOrganization] 
                      OPEN databaselist_cursor
                      FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
                      WHILE @@FETCH_STATUS = 0
                      BEGIN       
       PRINT 'Processing DATABASE: ' + @DatabaseName;
        SET @strSQL = 'DECLARE organizationlist_cursor CURSOR
        FOR SELECT '+ @DatabaseName +'.[dbo].[usGetLocationPathByRID]
                                   ([LocationRID]) 
        FROM '+ @DatabaseName +'.[dbo].[tblItemLocationDetailOrg] where
                                   ItemId = '+ cast(@ItemID as nvarchar(20))  ;
         EXEC sp_executesql @strSQL;
        -- Open the cursor
        OPEN organizationlist_cursor
        SET @localClientPath = '';
        -- go through each Location path and return the 
         FETCH NEXT FROM organizationlist_cursor into @clientLocation
         WHILE @@FETCH_STATUS = 0
          BEGIN
           SELECT @localClientPath =  @clientLocation; 
           SELECT @locationClientPath =
    @locationClientPath + @clientLocation + ','
           FETCH NEXT FROM organizationlist_cursor INTO
    @clientLocation
          END
           PRINT 'current databse client location'+  @localClientPath;
         -- Close the Cursor
         CLOSE organizationlist_cursor;
         DEALLOCATE organizationlist_cursor;
         FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
                    END
                    CLOSE databaselist_cursor;
                    DEALLOCATE databaselist_cursor;
                    -- Trim the last comma from the string
                   SELECT @locationClientPath = SUBSTRING(@locationClientPath,1,LEN(@locationClientPath)-  1);
                     PRINT @locationClientPath;
            I would like to create above query in function so that return value would be used in 
            another query select statement and I am using SQL 2005.
            I would like to know if there is a way to make this work as a function or any better way
            to  achieve this?
            Thanks,

    This very simple: We cannot use dynamic SQL from used-defined functions written in T-SQL. This is because you are not permitted do anything in a UDF that could change the database state (as the UDF may be invoked as part of a query). Since you can
    do anything from dynamic SQL, including updates, it is obvious why dynamic SQL is not permitted as per the microsoft..
    In SQL 2005 and later, we could implement your function as a CLR function. Recall that all data access from the CLR is dynamic SQL. (here you are safe-guarded, so that if you perform an update operation from your function, you will get caught.) A word of warning
    though: data access from scalar UDFs can often give performance problems and its not recommended too..
    Raju Rasagounder Sr MSSQL DBA
          Hi Raju,
           Can you help me writing CLR for my above function? I am newbie to SQL CLR programming.
           Thanks in advance!
           Satya
              

  • Creating PL/SQL web services from PL/SQL records

    Hello
    Jdeveloper does not allow to create web services from pl/sql packages that use PL/SQL records.to do this,we have to use the jpublisher ?without using the jpublisher,if we create a webservice then the following error is displayed in the web service xml output file.
    <faultstring>Internal Server Error (Caught exception while handling request: java.rmi.RemoteException: java.sql.SQLException: ORA-06550: line 1, column 49: PLS-00181: unsupported preprocessor directive '$WS_SP_EVEN' )</faultstring>
    </env:Fault>
    Could any one suggest me, how to solve the above issue..?
    Regards
    Malathi

    Thank you, with db adapter it was working and also
    pl/sql web-services working successfully with object types.If we want to send the web-services to the client, do we need to send the entire folder that is created in the web-services folder of the external oc4j..?
    Creating the client process:
    we are using the wsdl file that is generated in the web-services and adding to the partner link to Invoke the operations of web-services. Is there any other way to invoke the webservices?Could any one please suggest me?
    Thanking you
    Malathi

  • Creating PL/SQL web services from object types

    Hello
    Jdeveloper, pl/sql web-services working successfully with object types.If we want to send the web-services to the client, do we need to send the entire folder that is created in the web-services folder of the external oc4j..?
    Creating the client process:
    we are using the wsdl file that is generated in the web-services and adding to the partner link to Invoke the operations of web-services. Is there any other way to invoke the webservices?Could any one please suggest me?
    Thanking you
    Malathi

    Hello
    Accessing the pl/sql webservices from the application server:
    I have created pl/sql webservice using the nested tables. This will insert the object data into database tables.after deplying the webservice into external oc4j, when I test the webservice locally with url: http://localmachine:8888/PL_SQL_WS-Nest_Obj_Webservice-context-root/ObjWebserviceSoapHttpPort
    The above web-services working and I am able to insert into the database tables.
    Same when I want to access through the application server, I have changed the wsdl file soap address as
    <soap:address location="http://10.91.20.7:8888/PL_SQL_WS-Nest_Obj_Webservice-context-root/ObjWebserviceSoapHttpPort"/>
    When I access this url, I am able to give the input data
    http://10.91.20.7:8888/PL_SQL_WS-Nest_Obj_Webservice-context-root/ObjWebserviceSoapHttpPort
    but the out from the web-service is:
    <env:Envelope
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
    <env:Fault
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <faultcode>env:Server</faultcode>
    <faultstring>Error creating target: DBConnImpMftest.ObjWebserviceUser</faultstring>
    <faultactor/>
    </env:Fault>
    </env:Body>
    </env:Envelope>
    Err from the OC4j log:<PAYLOAD>
    <MSG_TEXT>An error occurred for port: {http://dbconnimpmftest/Nested_Webserv.wsdl}Nested_WebservSoapHttpPort: javax.xml.rpc.JAXRPCException: Error creating target: dbconnimpmftest.Nested_WebservUser.</MSG_TEXT>
    </PAYLOAD>
    Could any one help me to solve the above issue?
    Kind regards
    Malathi

  • Why i cannot create the sql azure database from my own country 'Nepal' ?. why it is not include in the list of country when we sign up for azure database. :( !!!

    why i cannot create the sql azure database from my own country 'Nepal' ?. why it is not include in the list of country when we sign up for azure database. :(  !!!
    canot we try this new feature ,dosnot we need to try this too..why such discermination for our country nepal. :(

    Hi Anil,
    I am Mahesh from Microsoft Innovation Center. From August 2014 we have made Azure Available to Nepal. You can now directly sign in to azure with your Nepal Based Mobile Number as Verification.
    Thanks for showing your Interest in our Product.
    Mahesh Dahal

  • Create Trigger (PK from Sequence) in SQL Developer 1.5.1

    Hi all
    I'm new to Oracle and am trying to create the equivalent of an autonumber field on a table using the Create Trigger (PK from Sequence) option (by right clicking on a table in SQL Developer).
    I've set up a sequence called REQUESTID and when using the above option it generates the following SQL:
    begin
    execute immediate 'create or replace trigger AutoNumber '||
         ' before insert on "REQUEST" '||
         ' for each row '||
         'begin '||
         ' if inserting then '||
         ' if :NEW."REQUESTID" is null then '||
         ' select REQUESTID.nextval into :NEW."REQUESTID" from dual; '||
         ' end if; '||
         ' end if; '||
         'end;';
         end;
    When I click Apply I get an ORA-00942 (table or view does not exist). Am I doing something daft here?

    Never mind - sorted it - I created the table under a different Schema to the System login being used in SQL Developer and so didn't have the permissions to create the trigger on the table.

  • Create oracle table from sql server

    Dear Gurus,
    I need to create some tables from sql server 2008 to a oracle 11g database. Some tables contain vbinary datatype. Now my queries are
    1. How can I do that?
    2. If DB link is a solution then would you please provide me a step by step process to do so?
    3. Is there any issue with datatype?
    SQL Server db is on windows 2008 R2
    Oracle is in RHEL 5.5
    Will appreciate ur help.

    well suppose i generate flat files from sql server and load in oracle by sqlloader then will there be any issue with vbinary datatype? what should be the equivalent data type in oracle table?

  • How to create database link from oracle to sql server

    Please help with how to create database link from oracle to sql server
    Best regards,
    Vishal

    Please help with how to create database link from oracle to sql server
    Best regards,
    Vishal
    Hi Vishal,
    I found a lof of information regarding how to create a database link from Oracle to SQL Server, please see:
    https://www.google.co.in/?gws_rd=cr&ei=vd3XUvGFO8TgkAXqlYCADg#q=how+to+create+database+link+from+oracle+to+sql+server
    We discuss SQL Server related issue in this forum. If you have any more question regarding Oracle, please post it in Oracle communities forum for better support.
    Regards,
    Elvis Long
    TechNet Community Support

  • Hi, I would like to create a database from my numbers spreadsheet and create reports (like SQL). Is there a way?

    Hi, I would like to create a database from my numbers spreadsheet and create reports (like SQL). Is there a way?

    Numbers is a lightweight spreadsheet.  If you know sql you will know that it can handle many queries and is a real databases that can handle many thousands of records.  Number is not the correct tool.  You can make something that does something like a query but it is not truly a query.
    Can you share anything about the specific application and how much information there is in each record?  How many records (rows)?

  • Creating PL/SQL Package with all the types

    CREATE OR REPLACE
    TYPE rec_type AS OBJECT (
    first_name VARCHAR2(20),
    last_name VARCHAR2(20)
    CREATE OR REPLACE
    TYPE REC_TYPE_TAB AS TABLE OF rec_type
    I am able to create the above types in oracle and used in PL/SQL packages. And like this I have somany types. I would like to if I can create a package with the types to make the life easier. Could you please tell me how to do it.
    your help is greately appreciated..
    --Krish                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    sb92075 wrote:
    TYPE add only aggravation, complexity, & should be avoidedI disagree.
    When used correctly types can be the simplest solution.
    For example when passing multiple values to a stored procedure. Avoiding the type in the below example would lead to further complexity and aggravation not lessen it.
    SQL> create or replace procedure p
      2      (
      3      p_object_list in sys.odcivarchar2list,
      4      p_result out sys_refcursor
      5      ) as
      6  begin
      7      open p_result for
      8          select owner, object_name, object_type
      9          from all_objects
    10          where object_name in
    11              (
    12              select column_value from
    13              table(p_object_list)
    14              )
    15          order by
    16              owner, object_name, object_type;
    17  end;
    18  /
    Procedure created.
    SQL> exec p(sys.odcivarchar2list('DUAL','ALL_OBJECTS'),:c)
    PL/SQL procedure successfully completed.
    SQL> print c
    OWNER                          OBJECT_NAME                    OBJECT_TYPE
    PUBLIC                         ALL_OBJECTS                    SYNONYM
    PUBLIC                         DUAL                           SYNONYM
    SYS                            ALL_OBJECTS                    VIEW
    SYS                            DUAL                           TABLE

  • Creating PL/SQL package in SQL Developer 4.0.0.12

    Hi,
    I have built a model in SQL Developer 4.0.0.12 and I want to create it's PL/SQL package.
    In ODMiner 11.1.0.4 from "Tools" > "Create pl/sql package" I can get a script for creating package and every thing is OK.
    but in SQL Developer I select "Deploy" from every node's context menu and it generates a folder containing some scripts related to every node. I don't see any relevant script for creating any package.
    How can I create relevant PL/SQL package from my workflow?
    Thank you for any help you can provide in this situation.

    Please refer to this White paper for how to generate PL/SQL package for workflow deployment:
    Oracle Data Miner (Extension of SQL Developer 4.0)
    Generate a PL/SQL script for workflow deployment
    http://www.oracle.com/technetwork/database/options/advanced-analytics/odmrcodegenwhitepaper-2042206.pdf

  • Database Initialiser does not create azure sql database

    I have a WPF application In the OnStartup in the app.cs I set the Database initializer and forced the context the initialise my database:
    Debug.WriteLine("Setting Initializer");
    Database.SetInitializer<MyContext>(new MyDatabaseInitializer());
    Debug.WriteLine("Declaring new context");
    using (MyContext c = new MyContext("MyContext"))
    Debug.WriteLine("Force the initialization");
    c.Database.Initialize(true);
    Debug.WriteLine("Done!");
    I created a sql database in the management portal of the azure.
    Copied the connectionstring it provided for ADO.net.
    But my database is not created.
    I also added a firewall rule but nothing happens. I Have no clue what to do.
    Can anybody please help me with this?
    If you need more information please ask i really have to get this sorted out.
    Thanks in advance!

    Hi Turkstra,
    I have tried to use EF to create Azure SQL database, it works as expect, the database 'jambordbcreate' appear in my SQL Azure, below is the detailed codes.
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace CodeFirst
    class Program
    static void Main(string[] args)
    Database.SetInitializer(
    new CreateDatabaseIfNotExists<SchContext>());
    using (var db = new SchContext("Server=tcp:****.database.windows.net,1433;Database=jambordbcreate;User ID=vote@***;Password=***;Trusted_Connection=False;Encrypt=True;Connection Timeout=30"))
    string name = "jambor";
    var student=new Student(){Name=name, ID="1a"};
    db.Students.Add(student);
    db.SaveChanges();
    db.Database.Initialize(true);
    public class Student
    public string ID { get; set; }
    public string Name { get; set; }
    public string age { get; set; }
    public string sex { get; set; }
    public class School
    public string ID { get; set; }
    public string Name { get; set; }
    public virtual List<Student> Students { get; set; }
    public class SchContext : DbContext
    public SchContext(string connection):base(connection)
    public DbSet<Student> Students { get; set; }
    public DbSet<School> Schools { get; set; }
    I suggest  you check your SQL connection, after run your code, please refresh azure portal to see whether your database is exist. Hope this give you some help.
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for