SQL Server Performance

select ? as an input parameter

Discussion in 'SQL Server DTS-Related Questions' started by cronid, Oct 17, 2006.

  1. cronid New Member

    I am trying to pass a calculated date to my SQL task by using the syntax:

    SELECT ?, ANY_COLUMN FROM MYTABLE

    I get the error message 'Syntax error or access violation'. The date would ordinarily be today except on Saturdays when I bump it to the following Monday.

    Can't I do this? What is the syntax error?
  2. ranjitjain New Member

    try this
    SELECT getdate(),column from table
  3. cronid New Member

    I don't want getdate(). I want the date I've calculated.
  4. ranjitjain New Member

    declare @var1 datetime
    select @var1=getdate()--or the way u r calculating
    select @var1,column from table
  5. cronid New Member

    I'm sorry - I've stated my problem poorly. I can think of a number of work arounds including the ones suggested but I want to be able to use the input parameter for a SQL statement. I believe the statement

    Select count(*) from mytable where name=?

    will allow for a specified global variable to be the input parameter substituted for the question mark. I thought the same would be true for my query above where the question mark is in the select, not the where clause. I want to know if I'm making a syntax error or is it some other problem.
  6. mmarovic Active Member

    I think it is only possible to pass parameters to stored procedure execution. I am not quite sure about that, but you can try and see if it helps.

Share This Page