3

I have a table with 3 columns and sample data like this:

enter image description here

All columns are of datatype int.

I have this query :

select 
    foodid, dayid 
from 
    Schedule

I want replace dayid with a string if dayid=null .

For this I tried this query :

select 
    foodid,
    Dayid + ISNULL(dayid,'not day') 
from Schedule

but I am getting this ERROR :

Conversion failed when converting the varchar value 'not day' to data type int.

How can do this ?

5
  • Please post the desired results based on your sample data. Commented Mar 1, 2015 at 16:04
  • I want replace dayid with a string id dayid=null it will be null so what different you want? Commented Mar 1, 2015 at 16:04
  • Specify your RDBMS,. Commented Mar 1, 2015 at 16:05
  • Try select foodid,ISNULL(dayid,'not day') from Schedule In your query you are trying to add (dayid + ...). Commented Mar 1, 2015 at 16:08
  • @PM77-1 Scheduleid is primary key , and other fileds are foreign key. Commented Mar 1, 2015 at 16:09

1 Answer 1

4

please try with this:

select foodid, ISNULL(str(dayid),'not day') from Schedule
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.