How to convert varchar to decimal format? SQL Server [closed] - sql-server

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am working with Pharmacy drug pricing data. The data resource I am using references drugs in the following format:
NDC: 0002831517
AWP: 001539667
AWP value has this format:
Decimal, 4 digits before, 5 digits after
So I would be looking to see:
AWP: 0015.39667
Whenever I use CONVERT, I get the following error:
Arithmetic overflow error converting nvarchar to data type numeric.
Any assistance would be greatly appreciated. Thank you!
EDIT: My SQL Logic:
SELECT TOP 1000 NDC10,
CONVERT(DECIMAL (9, 5), AWPUPRICE)
FROM [TEST].[dbo].[NDC_CODES]

You can try this:
SELECT TOP 1000 NDC10, CAST(LEFT(AWPUPRICE,4) + '.' + RIGHT(, 5) AS DECIMAL(9,5))
FROM [TEST].[dbo].[NDC_CODES]

Related

Google sheets Query >= function not working [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
I am trying to make a simple dashboard to get data from one sheet to show if it is greater than a week in cell B2
=QUERY('KPI 14 - 26'!A1:CC14,"select A, sum(F), sum(D), count(D)
where A is not null
AND A >= '"&B2&"'
group by A")
This code doesn't throw an error, but just doesn't display any date. If I change >- to contains it will show one weeks data. How can I fix this so that it shows all the data in weeks > week b2?
All of the data in column A on my data sheet are numbers (14 to 26)
use:
=QUERY('KPI 14 - 26'!A1:CC14,
"select A,sum(F),sum(D),count(D)
where A is not null
and A >= "&B2*1&"
group by A")

using min value in where query sql server [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a data in table like this :
==============================================================================================
id idPaper Code Sequential
==============================================================================================
1A506D10-9306-495A-9E4E-7081E3D3ACDB F4CFE90D-0921-4FB7-A236-5420B0892379 0036 2
3DB0FEBF-FBDF-4768-B36A-83AF4FB53E4B F4CFE90D-0921-4FB7-A236-5420B0892379 0035 1
I want display data like this :
==============================================================================================
id idPaper Code Sequential
==============================================================================================
3DB0FEBF-FBDF-4768-B36A-83AF4FB53E4B F4CFE90D-0921-4FB7-A236-5420B0892379 0035 1
1A506D10-9306-495A-9E4E-7081E3D3ACDB F4CFE90D-0921-4FB7-A236-5420B0892379 0036 2
I run my query:
select *
from tablename
where idPaper = 'F4CFE90D-0921-4FB7-A236-5420B0892379'
and min(sequential)
but it does not work. Please help me...
Thanks...
I think you just want to sort the data. Perhaps you just want:
select *
rom tablename
where idPaper='F4CFE90D-0921-4FB7-A236-5420B0892379'
order by sequential;
You can use order by.
select *
from tablename
where idPaper='F4CFE90D-0921-4FB7-A236-5420B0892379'
order by sequential

oracle formatting ==> to_char(12.222,'000000000009') gives me output as 000000000012. How can I get same format in TSQL? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
oracle formatting ==>
select to_char(12.222,'000000000009') from dual gives me output as 000000000012.
select to_char(1,'000000000009') from dual gives me output as 000000000001.
select to_char(12,'000000000009') from dual gives me output as 000000000012.
How can I get same format in TSQL?
Let me try to elaborate more. I want the number to be formatted in TSQL as it formats in Oracle. Say, if I enter 1 oracle query appends 11 zeros before 1. If i enter 12.22 then oracle query appends 10 zeros before 12.(Note that decimals are not considered)
similarly if i enter 123 then output will be 9 zeros appended before 123.
Do you want this?
DECLARE #i int=12
DECLARE #digit_number int =10
SELECT REPLICATE('0', #digit_number-LEN(cast(#i as varchar(50))))+cast(#i as varchar(50))

ORACLE select lacks row [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I use ORACLE setup RAC cluster.
My problem is when DB got problem (still dont know the reason ) my sql select lacks rows
example:
select *
from student_detail
where student_id = 1231
should return 10 row data of student have id 1231, but in this case just return 6 rows
can anybody help me to understand this problem!
As a general observation, an Oracle SELECT always returns the correct number of rows. If the result set does not match your expectation then there is a problem with your understanding.
For instance you may have miscounted the number of rows with student_id = 1231. If the query returns only six rows how do you know there are supposed to be ten? It might not be as simple as eyeballing ...
select * from student_detail
order by student_id
... if student_id has a varchar2 datatype and some IDs are suffixed with stray spaces. A query like this will diagnose that problem:
select student_id, count(*)
from student_detail
group by student_id
order by student_id
Other possible causes? A misleading view? Row Level Security restricting the result set? Some bizarre client-side configuration which only shows the first six rows instead of the entire set?
You mention RAC. RAC uses a mechanism called the Global Cache Service Process to transmit changed data to different nodes. It is possible you are experiencing a failure in this process. Talk to your DBA and get them to investigate.
Maybe, the data should be wrong.
for example, if the data of user_id is '1231', that's not wrong, but if the data is left gap
like ' 1231', you can't see the data.
' 1231 ' , '1231 ' also can not be printed out.
The solution is when you insert some data, use the function 'trim' or 'replace'...
trim is only remove left gap.

Excel dd-MM-YY format formula [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
i have a excel sheet with mixed date format.
Like 15-05-81 and the normal datetime Format 11/07/1990 00:00:00..when i am importing thses to a Database, The non date format give me a null.Is there anyformaula i can convert the text date to a datetime format ?
Thank You !
Try this:
Highlight the entire date column in your spreadsheet
Press Ctrl+H
Enter find what: -
Enter replace with: /
Click replace all
This will convert "11-07-90" into "11/07/90".
You may run into problems if the date to be converted has the wrong order also (ie. dd-mm-yy would result in dd/mm/yy which is wrong, the standard format is mm/dd/yy).

Resources