Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 955225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:20:45+00:00 2026-05-16T00:20:45+00:00

I have an issue where a variable is not getting set by a select

  • 0

I have an issue where a variable is not getting set by a select statement.

The select joins a table variable @contracts (which is used to control a loop) and then joins to the real contract and contract line tables.

my select is:

select top 1 
        @contract_id = c.contract_id 
        , @account = ch.account
        , @service = cl.service
        , @model = cl.model
        , @serial = cl.serial
        , @contract = ch.contract
    from 
        @contracts c
        inner join contractline cl on c.contract_id = cl.contract_id
        inner join contractheader ch on cl.contract = ch.contract
    where
        cl.contract_id = @contract_id

But when I do a select @contract_id say i get a NULL back, as do all my variables.

I have done a simple select * from @contracts c inner join contractline cl on c.contract_id = cl.contract_id inner join contractheader ch on cl.contract = ch.contract and this returns exactly 1 line with the values in all the correct places, no nulls in the selected values.

What have I done wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:20:46+00:00Added an answer on May 16, 2026 at 12:20 am

    Looks like your WHERE clause could be stopping the row from returning. You mentioned you’ve tested the same SELECT without setting variable, but the code you listed doesn’t include this WHERE – so its not the same.

    Test your SELECT with the WHERE in place, with dummy values (likely NULL) and review. It simply sounds like its not returning a result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll need to use DOM mutation events . This (untested)… May 16, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer The problem ist not alerting the json or not it's… May 16, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer My guess is that your file is not there. In… May 16, 2026 at 5:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

using javascript I have a function function test(variable) { if(variable != 'undefined') { console.log('variable
I have got the following issue, my function appends code to a string $string
I have installed TortoiseSVN in the C:\Program Files\TortoiseSVN folder. In the Environment Variable window,
I have a php page which allows a user to sort pieces of information
I am trying to merge records from an Oracle database table to my local
I am getting an error with this in php. What is the correct way
EDIT I solved the issue by forking the process instead of using threads. From
I am attempting to create a MySQL snippet that will analyse a table and
I'm having issues with getting DBI's IBM DB2 driver to work with mod_perl. My
I have some Javascript that dynamically adds rows/fields when you click the button, Add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.