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 6329353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:38:46+00:00 2026-05-24T17:38:46+00:00

I am having problems with a query. SELECT table_1.element_description, table_1.element_id, ISNULL(exercise_time_taken, ’00:00:00′) AS exercise_time_taken

  • 0

I am having problems with a query.

SELECT table_1.element_description, table_1.element_id, ISNULL(exercise_time_taken, '00:00:00') AS exercise_time_taken 
FROM (SELECT * FROM elements WHERE **`unit_id = 'ndb'`**) as table_1 
LEFT JOIN(SELECT CONVERT(CHAR(8), DATEADD(SS, SUM(DATEDIFF(ss, start_time, finish_time)),'20000101'), 108) AS exercise_time_taken, element_id 
FROM exercises 
WHERE exercises.user_id = 'my_email' **AND element_id <> ALL (SELECT unit_id FROM units)** 
GROUP BY element_id) as table_2 ON table_1.element_id = table_2.element_id

When i replace the highlighted line AND element_id <> ALL (SELECT unit_id FROM units)

WITH

element_id <> 'admin' AND element_id <> 'fc1' AND element_id <> 'ncc1' AND element_id <> 'ncc2' AND element_id <> 'nda' AND element_id <> 'ndb' AND element_id <> 'ngc1' AND element_id <> 'ngc1_demo' AND element_id <> 'ngc2' AND element_id <> 'ngc3'

Which is basically the long way of specifying which values not to select, the query runs fine a produced the desired output, if i dont do it this way then i get the ‘Conversion failed when converting the nvarchar value ‘ngc1′ to data type int’ error.

I would prefer not to manually code for each value as the list will grow over time and I will have to keep updating the query, which inevitably will be missed at some point causing more work than necessary.

Why does it do this? Even stanger depending on which unit i initially specify see sample line, it works for some and not others.

  • 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-24T17:38:47+00:00Added an answer on May 24, 2026 at 5:38 pm

    What is the data type of unit_id in the units table? If this is an int then that is why you are getting this error. It is trying to convert element_id to compare against your subquery values and the conversion fails.

    Try using the following code and see if it works:

    AND element_id <> ALL (SELECT CONVERT(VARCHAR, unit_id) FROM units)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with a SQL query. SELECT t.topicname, m. *, ms.avatar FROM
I'm having some problems with join query. What I want is select rows of
I'm having problems running a query ranking. The inner SELECT gives the rows in
Im having problems building a query with the linq to sql data query expression
I'm having problems with an SQL query used to display custom profile fields and
I am having problems with the following query in Castle ActiveRecord 2.12: var q
I'm having some problems trying to perform a query. I have two tables, one
I am having some problems turning the SQL below into a Zend Db query.
So, I'm having some problems with a MySQL query (see other question ), and
I am having a problem getting a list of fields from a query defined

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.