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
 General SQL Server Forums
 New to SQL Server Programming
 Format of numbers

Author  Topic 

deathrone
Starting Member

15 Posts

Posted - 2012-08-17 : 06:44:44
Hello everybody,

I'm new user here. I've just finish my first degree of econometrics and started my career as analysit in risk management in Poland. I donno SQL in practice so now i would like to answer ya little question:

f.x. We've got:

SELECT count(blabla) suma
FROM jabadabu
GROUP BY trololo

and the result is:
suma
4564654
54646
216311
321321
etc.

how to make the result like this:
suma
4 564 654
54 646
216 311
321 321
etc.

??

trololoolo

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-08-17 : 09:47:44
generally , it is better to do this sort of formatting at the presentation layer . But if you must, this is one method.

declare @num INT
set @num = 4564654
select replace(replace(convert(varchar,cast(@num as money),1), '.00',''),',',' ')


Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

deathrone
Starting Member

15 Posts

Posted - 2012-08-20 : 03:29:58
thx man! i dont understand that perfectly but i have a lot of fuckin time to learn, cuz i will be as good as ya some day... ;)

can ya tell me one thing more: how to choose one record, with maximum date. I wrote this:

select * from tabela
where date=max(date)

but this doesn't work :(

trololoolo
Go to Top of Page

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2012-08-20 : 04:28:54
deathrone, some friendly advice. Please don't use vulgar language.
Go to Top of Page

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2012-08-20 : 04:36:13
See this: http://msdn.microsoft.com/en-us/library/ms173454.aspx
and this: http://msdn.microsoft.com/en-us/library/ms187751

Go to Top of Page

deathrone
Starting Member

15 Posts

Posted - 2012-08-20 : 04:47:18
yee i tried to use limit/top/rownum but it doens't work too :(


select * from tabela
where rownum <2
order by date

Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, '.', /, <, <=, <>, =, >, >=, ?, AND,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.

:(

trololoolo
Go to Top of Page

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2012-08-20 : 04:50:40
Something like this:



select a.*
from tabela as a
where a.date= (select max(date)
from tabela as b
where a.ID = b.ID)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-20 : 05:11:10
deathrone, are you using MS SQL Server ?

FYI, SQLTeam.com is on Microsoft SQL Server. For other DB systems, try dbforums.com


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

deathrone
Starting Member

15 Posts

Posted - 2012-08-20 : 05:13:01
yup Abu-Dina, that idea is logic and shou be ok but the SAS compilator says now:
ERROR 76-322: Syntax error, statement will be ignored.

Khtan: I use oracle database i think, cuz i'm writtin it in SAS, proc SQL.

trololoolo
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-20 : 05:21:52
For Oracle, try posting your question at http://www.dbforums.com/oracle/


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

deathrone
Starting Member

15 Posts

Posted - 2012-08-20 : 05:28:41
ok, bro. That forum is nice.

trololoolo
Go to Top of Page
   

- Advertisement -