Solved

sql with qty slash price

Posted on 2014-02-10
4
281 Views
Last Modified: 2014-02-10
Error converting data type varchar to numeric
,'BasePrice'=Case when BaseStorePrice = 1 then BaseStorePrice
else  CAST((CAST(BaseStoreQty AS VARCHAR(100))) AS VARCHAR(100)) + convert( varchar(30), '/' ) + CAST(BaseStorePrice AS VARCHAR(100)) end

Open in new window

0
Comment
Question by:sevensnake77
4 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39847624
What are you hoping to achieve with that?
0
 
LVL 5

Accepted Solution

by:
dannygonzalez09 earned 500 total points
ID: 39847625
give this a try

,BasePrice = Case when BaseStorePrice = 1
                        then CONVERT(VARCHAR(100),BaseStorePrice)
                        else CONVERT(VARCHAR(100),BaseStoreQty) + ' / ' + CONVERT(VARCHAR(100),BaseStorePrice)
End
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39847629
Paraphrasing the above T-SQL...

CASE
  WHEN BaseStorePrice = 1 THEN {a number }
  ELSE {a varchar} END

CASE blocks with multiple WHEN..THEN..ELSE have to return a value of the same data type, so in this case returning either a numeric 1 or a varchar 'the quantity / the price' won't work.

Try '1' instead of 1 so that both will return a varcahr.
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39847636
tks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now