dynamic sql with variable column name

I want to give select list(columan names) as variable to the dynamic sql
statement..

is this possible ?

sql statement that  I wrote below :

string Sqlstatement,sqlst1,Stringvar
decimal decvar
Sqlstatement = 'SELECT  ?   FROM TABLE_NAME
WHERE TABLE_NAME.COLUMN1 ="'+variable1+'"  and &
      TABLE_NAME.COLUMN2 = "'+variable2+'"  and &
      TABLE_NAME.COLUMN3 = "'+variable3+'"  and &
      TABLE_NAME.COLUMN3 =  "'+variable3+'"'
        PREPARE SQLSA FROM :Sqlstatement ;
        DESCRIBE SQLSA INTO SQLDA ;
        DECLARE my_cursor DYNAMIC CURSOR FOR SQLSA ;
        SetDynamicParm(SQLDA, 1,variable_column_name )
        sqlst1=sqlstatement
        OPEN DYNAMIC my_cursor USING DESCRIPTOR SQLDA ;
        FETCH my_cursor USING DESCRIPTOR SQLDA ;

if I remove "?" and give a column_name (non variable) this statements works
fine.
But I want to give select list(columan names) as variable .
is this possible ?

Thank you in advance

Metin Arslan
metin.arslan@inoksan.com.tr






1
metin
5/14/1999 2:07:58 PM
sybase.powerbuilder.general 62418 articles. 17 followers. Follow

1 Replies
947 Views

Similar Articles

[PageSpeed] 4

I'm not sure exactly where you're going with this, but you might try
transaction.SyntaxFromSQL(). Using this function, you can get datawindow
syntax from an SQL statement that you have built dynamically and then
retrieve the data into a DS or DW.

metin arslan wrote in message ...
>I want to give select list(columan names) as variable to the dynamic sql
>statement..
>
>is this possible ?
>
>sql statement that  I wrote below :
>
>string Sqlstatement,sqlst1,Stringvar
>decimal decvar
>Sqlstatement = 'SELECT  ?   FROM TABLE_NAME
>WHERE TABLE_NAME.COLUMN1 ="'+variable1+'"  and &
>      TABLE_NAME.COLUMN2 = "'+variable2+'"  and &
>      TABLE_NAME.COLUMN3 = "'+variable3+'"  and &
>      TABLE_NAME.COLUMN3 =  "'+variable3+'"'
>        PREPARE SQLSA FROM :Sqlstatement ;
>        DESCRIBE SQLSA INTO SQLDA ;
>        DECLARE my_cursor DYNAMIC CURSOR FOR SQLSA ;
>        SetDynamicParm(SQLDA, 1,variable_column_name )
>        sqlst1=sqlstatement
>        OPEN DYNAMIC my_cursor USING DESCRIPTOR SQLDA ;
>        FETCH my_cursor USING DESCRIPTOR SQLDA ;
>
>if I remove "?" and give a column_name (non variable) this statements works
>fine.
>But I want to give select list(columan names) as variable .
>is this possible ?
>
>Thank you in advance
>
>Metin Arslan
>metin.arslan@inoksan.com.tr
>
>
>
>
>
>


1
Erich
5/14/1999 7:38:53 PM
Reply:

Similar Artilces:

Column Name with Dynamic SQL
Hi, I use DynamicStagingArea for retrieval of a dynamic table. I there any possibility to get the column names for the table? Roland Sattler ...

Dynamic column names in T-SQL?
Does anyone know of a clever hack that can be used to generate column names on the fly, either from local variables or values in a temp table? Robert Gumpertz wrote: > > Does anyone know of a clever hack that can be used to generate column names > on the fly, either from local variables or values in a temp table? For what purpose? I'm not following where you're going with this? (maybe I need some caffeine?) -- Mark A. Parsons Iron Horse, Inc. This is a reporting application where the user can submit a random list of states; the result is a count by categ...

Variable table name in dynamic SQL
Using Dynamic SQL (format 4) is it possible to make a table name variable? I get a SQL error: error near 'site' and SQLDBCode 102 when I try this: String SqlStmt = "SELECT count(*) FROM ? " PREPARE SQLSA FROM :SqlStmt using tDest; // tDest is valid! DESCRIBE SQLSA into SQLDA ; DECLARE row_count DYNAMIC CURSOR FOR SQLSA ; SetDynamicParm(SQLDA, 1, "site") OPEN DYNAMIC row_count USING DESCRIPTOR SQLDA; The OPEN fails with SQLDBCode 102 and SQLErrText: SQL error near 'site'. If I change the SQL to put in a fixed table name and add 'WHE...

Dynamically setting the column name on a SQL query
Can anyone show me or tell if the following is possible. I have a SQL query as shown below: SQL = "SELECT revenue_forecast.oct AS 'revenue' ........... What I need to do is dynamically set the column in this SQL query. So i need to be able to place a variable in the part after the revenue_forecast "." . Can someone show me how to do this? Thanks It depends on your data source, but most data sources do not allow you to parameterize column names. You have a couple of choices. One is to concatenate the name into the string as in... SQL = "SELECT reven...

table names and column names as local variables
Hi, can anyone tell me if there's some way to call a select statement in wich the table name or column name is provided by a local variable? Like this declare @column_name varchar(30) declare @table_name varchar(30) select @column_name='pub_name' select @table_name='publishers' select @column_name from @table_name Thanx in advance > Hi, can anyone tell me if there's some way to call a > select statement in wich the table name or column name is > provided by a local variable? Like this > > declare @column_name varchar(30) > ...

Dynamically name columns in dynamically created datagrid
I am using code that I found on the net to take a datatable, drop it into a datagrid, and then export the whole thing as an excel spreadsheet. So far for the small numberes I have tried it works. Currently I have an application where the number of columns ranges between 40 and 70. The problem that I have is I want the first row to have names which are meaningful to the user, but I don't want to rename my datatable columns, only the datagrid columns. Right now the Excel column names are the same as the datatable names. Those names are meaningful to me (the programmer) but meaningless to...

SQL: Column names, can ONLY get "name" instead of "table.name"
Hey all, When iterating through column names returned from a query, I need to get "table.name" rather than just "name" Check it out: If I have an SQL statement "SELECT table1.ID, table2.ID FROM table1, table2;" And table1 has a column name 'ID' and table2 has a column name 'ID' aswell, and i run the query, the dataset will contain column names 'ID' and 'ID' instead of 'table1.ID' and 'table2.ID' It is extremely important that I can differenciate between the 2 fields, and know where each of them come from. The same thing happen...

How to use a full column name (table name and column name) with a DataReader
Hi, I have a problem retrieving the data with a DataReader from a stored proc that performs a join of two table with the same column's names but different data. Let me explain with an example: I have two tables: Table1: Id, Name Table2: Id, Name, IdTable1 The sproc is something like this: CREATE PROCEDURE [dbo].[SearchByName] (@Name nvarchar(40)) AS BEGIN SELECT * FROM dbo.Table1, dbo.Table2 WHERE Table1.Id = Table2.IdTable1 AND Table1.Name LIKE '%' + @Name + '%' END And my c# code is something like this: Database db = Databas...

SQL query returns 'No column name' as a column heading
 hi,I'm trying to execute this query in SQL Server 2005 Express Edition, the problem is in the column heading of the result for the majorName fieldSELECT studentID,fname,mname,lname,familyName,gpa ,(SELECT majorName AS major FROM major WHERE majorID=(SELECT majorID FROM studentmajorWHERE studentID='0000000'))FROM student WHERE studentID='0000000'; Why the result of this query returns 'No column name' as a label for the majorName field? I use the AS clause to allows the column to be named, the column heading of the result table still 'No column name&...

Dynamic column name?
Hi All, I am having one doubt which is mentioned below. My doubt is i want to store a column name in the instance variable. By using the instance variable i want to check the validation in itemchanged event.Is it Possible.....? Eg: In the itemchanged event i want check the column like this. This.Object.is_name[row] //where is_name contains some column name. You could use the older Describe method. Dot notation requires a fixed name. On 22 May 2004 08:25:55 -0700, Kalyan wrote: >Hi All, > >I am having one doubt which is mentioned below. > >My doubt is...

Dynamic column names
How to add column names for a data window object at run time ? ( The datawindow object has already been created) If you mean, assigning new names to existing columns at runtime, I don't believe you can do that. If you mean creating a new one, here's a snippet from the DWSyntax utility: <DW Control Name>.Modify(& "create column( id=<an integer> tabsequence=<an integer> accelerator='<a single letter>' moveable=<0 - False, 1 - True> resizeable=<0 - False, 1 - True> pointer='<Arrow!, Cross!, HourGlass!, IBeam!, Ico...

how to variable column names
Can anyone tell how to specify a column name in an update query which is stored in a local variable. What I want to do is: update #MyTable set @RatingColumn = 200 In the above query @RatingColumn is a local variable which stores the column determined on the fly from a result from a cursor. Thanks in advance. You can use the existing EXECUTE IMMEDIATE functionality: declare @cmdstring varchar(255) select @cmdstring = "update #MyTable set "+@RatingColumn+" = 200" execute (@cmdstring) -bret Niel_Junea wrote: > Can anyone tell how to sp...

column name through a variable?
Is there a way to pass the name of a column through a variable? For example, in ISQL I want to extract the column LastName from the table People CREATE VARIABLE @ColName CHAR(30); SET @ColName='LastName'; SELECT @ColName FROM People; In this example I obtain: LastName LastName LastName .... Which is not exactly what I hoped for :) Thank you in advance. c.r. You could use EXECUTE IMMEDIATE for a singleton select but not a multi-row select until version 9 comes out (soon :) Breck On Thu, 24 Jul 2003 15:17:33 +0200, "Robin" <.@iol.it> wrote:...

Can i use variable name as field name in power builder sql statement ?
Can i use variable name as field name in power builder sql statement ?like if m_field_name is a variable with value of a fieldname of a table named testtable how i can update the table update "testtable" set m_field_name = 10 ; is giving error please help Lookup "Dynamic SQL Format 2" in the online help -- Simon Caldwell Get Real Systems Ltd Holtby Manor, Stamford Bridge Road, York, YO19 5LL Tel 01904 481999 Fax 01904 481666 Visit us at www.getrealsystems.com Specialists in e-Procurement and supply chain technology <MNAIR> wrote in mess...

Web resources about - dynamic sql with variable column name - sybase.powerbuilder.general

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

YouTube v10.32 Tweaks Some Interface Elements And Includes Hints About Virtual Reality Content And Variable ...
Forget Update Wednesday! Monday is the new big day. Not only were we treated to the latest M preview release and the official Marshmallow name, ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Staley: 'A lot of different variables...been a hard year'
... 41° Navigation Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Staley: 'A lot of different variables...been ...

Expert Reveals the Latest Variable Capacity Technology
Learn about gForce Ultra CRAC equipment, the latest variable capacity technology to lower energy usage and increase reliability.

Resources last updated: 1/12/2016 7:24:58 AM