CFF KB - Carrz-Fox-Fire Promotions Knowledge Base

CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.
  • Breadrumbs:
  • Must declare the scalar variable "@ColNames".

  • CFF Knowledge Base - Share With Facebook CFF Knowledge Base - Share on Twitter CFF Knowledge Base - Share on Reddit CFF Knowledge Base - Share on Digg It CFF Knowledge Base - Share on Stumble Upon It CFF Knowledge Base - Share on Delicious
    Share With Friends (Updated 6-8-2010)
  • Article ID:
    6248
  • Date Created
    Thursday, June 2, 2022
  • This Article Has been Viewed
    405 times
  • Short Desc
    The select statement gives the error Must declare the scalar variable during testing
  • Details
    In ASP.NET, you may sometime get in a hurry and misspell the column name, causing the error Must declare the scalar variable. This happens in development and can frustrate a developer, especially if they are in a crunch situation.
  • Recreate Issue
     
    select colOne, ColTwo from TableOne where ColOne=@CoOne


    In the above example, the @CoOne is missing the l.
    Causing the error, as the @ column name is the scalar name.
  • Resolve Issue
    Looking at the code example above, we know that the @CoOne is not the correct way to spell the column name, thus giving us the error.
    We need to make sure that we spell the Column name correctly for both sides of the = sign to correct the error.

     
    select colOne, ColTwo from TableOne where ColOne=@ColOne