Solved

How to find all values in a column which is not money

Posted on 2016-11-11
25
41 Views
Last Modified: 2016-11-11
Hi,

How to find all values in a column which is not money datatype
0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 8
25 Comments
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41883532
Try..

--

SELECT [col_names] FROM TABLENAME 
WHERE COLNAME NOT LIKE '%.%' AND COLNAME NOT LIKE '%.00%' 

--

Open in new window

0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41883583
How to find all values in a column which is not money datatype
What's the column data type then?
0
 

Author Comment

by:RIAS
ID: 41883584
It is nvarchar(50)
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41883586
Wondering why are you storing money in a nvarchar field.
So, how's those money values formatted in that column?
1
 

Author Comment

by:RIAS
ID: 41883587
Thats the point i ma changing the datatype but, need to know the data which is not in money format
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41883588
Try..

--

CREATE TABLE a
(
	a VARCHAR(100)
)
GO

INSERT INTO a VALUES ('2.34'),('5.0'),('5'),('13.2'),('Pawan'),('13.2')
GO

SELECT * FROM a 
WHERE a NOT LIKE '%.%' AND a NOT LIKE '%.00%' 

--

Open in new window


Output
---------
a
5
Pawan
0
 

Author Comment

by:RIAS
ID: 41883589
Pawan,
 There is aproblem with you query its returning even
10900
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41883590
Thats the point i ma changing the datatype but, need to know the data which is not in money format
For help you I need to know how a money value is stored in that field. Can you provide a sample?
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41883592
Hi Rias,
Have you tried the code I gave. <<Check out the example One>>

Regards,
Pawan
0
 

Author Comment

by:RIAS
ID: 41883594
Vitor,

Example:

NULL
$43,869.60
£10,000.00
£235,847.99
£266,941.14
£486,704.27
1, 029.000.00
1, 603, 571.10
1,000,000.00
1,055.00
1,066,069.80
1,100.00
1,209,454.44
1,250.00
1,277,877.27
1,328,837.00
1,436,880.00
1,457.50
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41883595
You should mark which ones are considered money or we just assume everything that has numbers are money?
0
 

Author Comment

by:RIAS
ID: 41883597
yes, we just assume everything that has numbers are money
0
 
LVL 29

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 250 total points
ID: 41883598
Try

[code]
--

CREATE TABLE a
(
	a VARCHAR(100)
)
GO

INSERT INTO a VALUES 
(NULL),
 ('$43,869.60'),
('£10,000.00'),
('£235,847.99'),
('£266,941.14'),
('£486,704.27'),
 ('1, 029.000.00'),
 ('1, 603, 571.10'),
 ('1,000,000.00'),
 ('1,055.00'),
 ('1,066,069.80'),
 ('1,100.00'),
 ('1,209,454.44'),
 ('1,250.00'),
 ('1,277,877.27'),
 ('1,328,837.00'),
 ('1,436,880.00'),
 ('1,457.50' )

GO

SELECT * FROM a 
WHERE a NOT LIKE '%.%' OR a IS NULL 

--

Open in new window


Output
---------
a
NULL

[/code]
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41883600
Ok, then this should work:
SELECT *
FROM TableName
WHERE ISNUMERIC(ColumnName) = 1

Open in new window

0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41883602
Hi Rias,

Any luck ?
0
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 41883603
Looks like you want the opposite (not money). So just change the filter:
SELECT *
FROM TableName
WHERE ISNUMERIC(ColumnName) = 0

Open in new window

0
 

Author Closing Comment

by:RIAS
ID: 41883604
Thanks!
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41883606
@Rias - You cannot accept Incorrect solution. His both solutions are giving incorrect outputs. Please note that these solution will be referred by people in future.

Both see below -


SELECT *
FROM a
WHERE ISNUMERIC(a) = 0

O/p

NULL
1, 029.000.00
1, 603, 571.10


SELECT *
FROM a
WHERE ISNUMERIC(a) = 1

Output
------

$43,869.60
£10,000.00
£235,847.99
£266,941.14
£486,704.27
1,000,000.00
1,055.00
1,066,069.80
1,100.00
1,209,454.44
1,250.00
1,277,877.27
1,328,837.00
1,436,880.00
1,457.50
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41883612
Hi Rias,

Can you confirm whether Vitor Solution worked for you and how ?

Thank You in advance.

Regards,
Pawan
0
 

Author Comment

by:RIAS
ID: 41883617
Pawan,
Just give sometime.Will get back on this .
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41883622
Those aren't numbers:
1, 029.000.00 --> Have an extra space and 3 dots
1, 603, 571.10 --> Have an extra space

If the author want to transform those values into a money field will fail.
So Pawan's solution won't work if let these values stays in the table.

Capture.PNG
3
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41883628
Okies. Cool. !!
0
 

Author Comment

by:RIAS
ID: 41883728
Thanks Vitor!!!
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41883744
Your welcome, RIAS.
Following Pawan's comment "@Rias - You cannot accept Incorrect solution." you should unaccept his solution. A couple of days ago you also gave him points for his "effort" (copying my solution and change a value) and that was also an incorrect solution.
I won't be picky with this (will let a moderator to decide what to do) but you should be more careful with the answers you're accepting. Sometimes is good to perform more tests before accepting immediately an answer. We aren't on hurry here. :)
Cheers
3
 

Author Comment

by:RIAS
ID: 41883745
Vitor,

 Went on some other task so could not test thoroughly but,will take a note of this.

Cheers
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

628 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