Results 1 to 7 of 7

Thread: Dyamic SQL Queries

  1. #1
    Geek_Guest
    Guest

    Dyamic SQL Queries

    Please Give some examples for Dyamic SQL Queries

    Question asked by visitor LAKSHMI


  2. #2
    Junior Member
    Join Date
    Feb 2007
    Answers
    17

    Re: Dyamic SQL Queries

    Hi,

    Following is one example of dynamic query

    Declare @TableName varchar(128), @ColumnList varchar(1000)
    Declare @SQL varchar(1000)

    set @TableName = 'authors'

    SELECT @ColumnList = COALESCE(@ColumnList + ', ', '') + column_name
    FROM INFORMATION_SCHEMA.Columns
    WHERE Ordinal_position <= 10
    and table_name = @TableName

    Set @SQL = 'Select ' + @ColumnList + ' from ' + @TableName


  3. #3
    Junior Member
    Join Date
    Jun 2007
    Answers
    18

    Re: Dyamic SQL Queries

    IN oracle
    & is used for dynamic sub
    eg SELECT * FROM table
    WHERE last_name=&name


  4. #4
    Contributing Member
    Join Date
    Apr 2006
    Answers
    46

    Re: Dyamic SQL Queries

    u give some problem corresponding dynamic sql to solve.


  5. #5
    Junior Member
    Join Date
    Aug 2007
    Answers
    7

    Post Re: Dyamic SQL Queries

    DECLARE @IntVariable int;
    DECLARE @SQLString nvarchar(500);
    DECLARE @ParmDefinition nvarchar(500);
    DECLARE @max_title varchar(30);

    SET @IntVariable = 197;
    SET @SQLString = N'SELECT @max_titleOUT = max(Title)
    FROM AdventureWorks.HumanResources.Employee
    WHERE ManagerID = @level';
    SET @ParmDefinition = N'@level tinyint, @max_titleOUT varchar(30) OUTPUT';

    EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable, @max_titleOUT=@max_title OUTPUT;
    SELECT @max_title;


    Check with sp_executesql help in SQL Server Help


  6. #6
    Contributing Member
    Join Date
    Apr 2006
    Answers
    46

    Re: Dyamic SQL Queries

    sorry i don't know sql server but if u want it in oracle i can do that.


  7. #7
    Junior Member
    Join Date
    Aug 2007
    Answers
    7

    Re: Dyamic SQL Queries

    Sorry Bhaski. I don't have idea in ORACLE


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact