9

I was just surfing the net and found a query something like:

sql  = "select milk_rate from special_milk_rate 
        where code_producer_id=? and effective_from <= ? 
        and effective_till >= ?"

what exactly this query means i means what is the use of ? in this statement.

and one thing more what is use of & in sql.

Cœur
  • 37,241
  • 25
  • 195
  • 267
codeomnitrix
  • 4,179
  • 19
  • 66
  • 102

6 Answers6

11

This usually implies a prepared statement, where the parameters are filled in later. (see e.g. http://en.wikipedia.org/wiki/Prepared_statements#Parameterized_statements).

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
2

what exactly this query means i means what is the use of ? in this statement.

The question marks are for parameters.

and one thing more what is use of & in sql.

& is a bitwise AND operator in sql

RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262
1

Question marks are found in prepared statements, meaning it is parametrized and can be called again and again without having to reconstruct the whole sql statement, just by changing the parameters. Some frameworks use those that together with SqlCommands. Those encapsulate escaping and prevent sql injection attacks.

Some frameworks also allow named parameters.

Femaref
  • 60,705
  • 7
  • 138
  • 176
  • Do not confuse terminology of some library you use with SQL concepts. There is no such thing as a "SqlCommand" in many platforms and languages where such a query would appear. – Dan Grossman Jan 23 '11 at 12:46
1

The question marks are supposed to contain the actual parameters.

E.g.

"select milk_rate from special_milk_rate 
        where code_producer_id=2 and effective_from <= '20101231' 
        and effective_till >= '20110124'"
peakit
  • 28,597
  • 27
  • 63
  • 80
1

Here is nice article:

http://publib.boulder.ibm.com/infocenter/idshelp/v10/topic/com.ibm.sqls.doc/sqls610.htm#sii-02prep-18104

In some statements, parameters are unknown when the statement is prepared because a different value can be inserted each time the statement is executed. In these statements, you can use a question-mark ( ? ) placeholder where a parameter must be supplied when the statement is executed.

Naveed
  • 41,517
  • 32
  • 98
  • 131
1

& usually denotes a variable or substitution value which you may be prompted for at run time

Chris Cameron-Mills
  • 4,587
  • 1
  • 27
  • 28