Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Charindex

Author  Topic 

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-08-23 : 03:12:42
Hi gurus,
I am running this qry in QueryAnyalzer.But it return the values as 0. I dont know wy?

declare @nst as numeric
set @nst=12333.00
select charindex('.',@nst)


Can some body help

sutysw
Starting Member

3 Posts

Posted - 2007-08-23 : 03:28:50
declare @nst as numeric(10, 2)
set @nst=12333.00
select charindex('.',@nst)
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-08-23 : 04:36:06
Thanks Sutysw,
How can I use this with the select qry like
select charindex('.',field1) from tblname

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 04:38:52
It depends what you are trying to use it for.
I have no idea. You haven't told how yuo are going to use it.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-08-23 : 04:56:32
I want to retrive the column value with two decimal places.The column is of decimal dattype
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 05:02:02
quote:
Originally posted by danasegarane76

I want to retrive the column value with two decimal places.
What does this mean?

1) You want to get all records which has exactly 2 decimals in a DECIMAL(x, 2) column?
2) You want to get all records which is not ".00" at the end?
3) You want to round or truncate all records to 2 decimals?

If you considered explaining yourself more clearly, you might get the answer you want faster!



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 05:03:27
danasegarane76, please post

1) Your table structure
2) Some data from the table
3) Your expected output based on the data above



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-08-23 : 05:59:36
Dear Peter,
Thanks for ur reply.Here is the table structure and output requirment

create table test1
(
id int identity(1,1),
[name] varchar(10),
salary decimal(10,2)
)
insert into test1([name],salary) values('dana1',12365.0000)
insert into test1([name],salary) values('dana2',12365.12)
--Now I want to the out put as
-- [Name] salary
-- dana1 12365.0000
-- dana2 12365.12


Thanks in Advance
Dana
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 06:49:49
Since the table only holds TWO decimals, how can you expect FOUR decimals in the result?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-08-23 : 06:54:14
Oh Sorry,
I have changed the decimals as 8(Soory for the mistake).Now I can I retrive the values /

Dana
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 06:56:16
Did you use the ROUND(Salary, 2) function?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-08-23 : 08:29:29
Dear Peter,
I tried this one

select [name],round(salary,2) from test1

and it gave me the result as

dana1 12365.00000
dana2 12365.12000
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 10:38:54
Yes, and what do you expect?

SELECT [Name], CAST(Salary AS DECIMAL(8,2)) FROM Test1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-08-23 : 23:44:13
Thanks Peter,
Thats what i wanted . Thanks a Lot

Danasekarane
Go to Top of Page
   

- Advertisement -