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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:26:43+00:00 2026-05-22T02:26:43+00:00

If I have a table with columns like so: KeyName varchar(50) RowNumber int LocationValue

  • 0

If I have a table with columns like so:

KeyName varchar(50)  
RowNumber int  
LocationValue sql_variant  


select * from myTable where LocationValue = 'some string' -- no results, but no error
select * from myTable where CAST(LocationValue AS VARCHAR) = 'some string' --works

If LocationValue can contain either numeric or string data, is it mandatory to CAST that column to NUMERIC or VARCHAR in order to apply criteria to it?

Not doing so doesn’t cause any error, however no results are returned.

  • 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-22T02:26:44+00:00Added an answer on May 22, 2026 at 2:26 am

    It isn’t mandatory as such, but you need to CAST it to a meaningful type for that comparison: if only for maintainability and your sanity.

    The rules for conversions are here on MSDN. Above that, you have things on collation and SET ANSI_PADDING that will all affect results. An explicit CAST overrides these rules.

    I can’t actually say why you see this because I haven’t used sql_variant for years but I refer you to my first statement about “sanity”

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

Sidebar

Related Questions

I have a table which looks like this: mysql> SHOW COLUMNS FROM Users; +------------+--------------+------+-----+---------+----------------+
One of my database table columns have name like 'name@from' how can i write
Need some help. I have a table with some columns..like name , phone etc...
I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
I have table of 5000+ rows and 8+ columns like, Station Lat Long Date
I have a table products , and I have columns like product_name , product_id
I have a table with 3 columns ---QID---TEXT---CID--- I would like to find 20
In my table accounts I have four columns like user, pass, column1, column2 I
Well, I'll say it like this. I have a table with 2 columns. The
I have a table like T1 with columns C1 and C2. I have the

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.