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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:53:20+00:00 2026-05-29T05:53:20+00:00

select case when exists( select top 1 1 from dg_world_records wr (nolock) where wr.gametypeid

  • 0
   select case when exists(
                              select top 1 1 
                              from dg_world_records wr (nolock) 
                              where wr.gametypeid = 4 
                              and wr.playerid = 1
                           ) 
    then totaltime = (select min(totaltime) from dg_world_records (nolock) where playerid = 1 and gametypeid = 4)
    else totaltime = (select max(totaltime) from dg_world_records (nolock) where gametypeid = 4)
    end

My guess is that this can’t be done, but I’m trying to do a subselect within a sql case statement. Is this possible?

I’m trying to do a lookup based of finding or not finding a value in a table. I can do this by breaking up the statement, but I was wondering if it’s possible to do this in a single statement.

Here is the table schema:

CREATE TABLE [dbo].[DG_WORLD_RECORDS](
[WorldRecordId] [int] IDENTITY(1,1) NOT NULL,
[GameTypeId] [int] NOT NULL,
[PlayerId] [int] NOT NULL,
[NumberOfValues] [int] NOT NULL,
[TotalTime] [int] NOT NULL,
[DateOfRecord] [datetime] NOT NULL,
[GameId] [int] NULL,
[UTCInserted] [datetime] NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_UTCInserted]  DEFAULT (getutcdate()),
[UTCUpdated] [datetime] NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_UTCUpdated]  DEFAULT (getutcdate()),
[SrvName] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_SrvName]  DEFAULT (@@servername),

CONSTRAINT [PK_DG_WORLD_RECORDS] PRIMARY KEY CLUSTERED
(
[WorldRecordId] ASC
)
)

  • 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-29T05:53:21+00:00Added an answer on May 29, 2026 at 5:53 am

    Don’t know why you are writing this crazy query, but to answer your question, yes it could be done, just move your assignment out of the case statement:

    select totaltime = CAST (
       case when exists(
         select * 
         from dg_world_records wr (nolock) 
         where wr.gametypeid = 4 and wr.playerid = 1) 
        then (select min(totaltime) from dg_world_records (nolock) where playerid = 1 and gametypeid = 4)
        else (select max(totaltime) from dg_world_records (nolock) where gametypeid = 4)
        end AS INT)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my SQL: SELECT DISTINCT(CASE WHEN state=18 THEN lga ELSE 'Others' END) LGA,
I have this SQL query select case when AllowanceId is null then 2 else
I have (2) case statements: SELECT CASE WHEN EXISTS ( SELECT * FROM MYTABLE_A
i have this query SELECT CASE WHEN EXISTS (SELECT PARM_VALUE FROM BO_PARM WHERE (ENTE_CD
SELECT CASE schuleArtID WHEN 1 THEN SUM(schuleSummeSchueler) / 8 WHEN 2 THEN SUM(schuleSummeSchueler) /
I currently have a select-case that will read a name field from a recordset,
I have executed a code SELECT CASE b.ON_LOAN when 'Y' then 'In Lib' when
How to achieve the following query - SELECT CASE WHEN COUNT(*) > 0 THEN
So far, this query works using exists: SELECT CASE WHEN EXISTS ( SELECT *
select (case when t.freeplayabandoned != f.freeplayabandoned then 'freeplayabandoned' when t.freeplaydownloaded != f.freeplaydownloaded then 'freeplaydownloaded'

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.