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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Charindex
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

danasegarane76
Posting Yak Master

India
242 Posts

Posted - 08/23/2007 :  03:12:42  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
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 - 08/23/2007 :  03:28:50  Show Profile  Reply with Quote
declare @nst as numeric(10, 2)
set @nst=12333.00
select charindex('.',@nst)

Edited by - sutysw on 08/23/2007 03:29:25
Go to Top of Page

danasegarane76
Posting Yak Master

India
242 Posts

Posted - 08/23/2007 :  04:36:06  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/23/2007 :  04:38:52  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
242 Posts

Posted - 08/23/2007 :  04:56:32  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/23/2007 :  05:02:02  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/23/2007 :  05:03:27  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
242 Posts

Posted - 08/23/2007 :  05:59:36  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/23/2007 :  06:49:49  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
242 Posts

Posted - 08/23/2007 :  06:54:14  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/23/2007 :  06:56:16  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
242 Posts

Posted - 08/23/2007 :  08:29:29  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/23/2007 :  10:38:54  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
242 Posts

Posted - 08/23/2007 :  23:44:13  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
Thanks Peter,
Thats what i wanted . Thanks a Lot

Danasekarane
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000