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
I am executing this query in SQL Server 2008
SELECT (CONVERT(DATE, GETDATE()))
and it shows the result 2013-07-22.
I need to print this result as 22713, where 22 is the date 7 is the month 13 is the year.
How could I do this?
SELECT CAST(DATEPART(dd,GETDATE()) as varchar(10))
+CAST(DATEPART(mm,GETDATE()) as varchar(10))
+RIGHT(CAST(DATEPART(YY,GETDATE()) as varchar(10)),2)
SQLFiddle demo
1) It bad practice use SQL for string operation. More right external tools
2) I use other RDBMS. Below query work with it:
select (extract(day from ua.stamp))||(extract(month from
ua.stamp))||(extract(year from ua.stamp)) from useractions ua
Furthemote, this link can help you:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/55d23bb0-6e1e-4a03-9bed-94e7c755ec4d/get-the-day-from-date-value-in-sql-server
You could read the string, go over it with a tokenizer, split it and put it back together the way you want it to be. What language are you using?
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing the following SQL query:
SELECT *
FROM OS
WHERE OS.VERSION LIKE '%1%';
In my table there are rows with char 1 in it. However, it returns an empty result.
I changed a little bit the LIKE clause to different values, but it still doesn't work.
What can I do to fix that?
Try double-quotes and * for wildcards. You are using Oracle syntax instead of Access syntax.
LIKE operation can't be used with columns of integer type. I assume that OS.Version is of integer type?
Edit1:
If you are referring to MS Access then you have to do the LIKE with stars (*) instead of %.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a database table that contains a column for pricing.
Its very old, so it was written before i understood datatypes. so we are using varchar for a money value.
Ive noticed some columns have $ in them, so what I'm wondering is... is there a way with SQL Server to perform an update of the table and remove any instances of non numeric characters or at the very least remove the $ from the string in the columns in one go ?
I hope this is possible.
Update tbl
SET price = replace(price, '$', '')
Here is the replace definition
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
I have a string like this:
i would like to go to office, and i would like to go to market
My question is: how many times the word like occurs in the string?
Please write a query.
You can use regexp_count:
SELECT REGEXP_COUNT('i like to go , and i would like market', 'like')
FROM DUAL;
The word "like" occurs twice in the string you posted.
The following is a query:
SELECT *
FROM SOME_TABLE
WHERE SOME_VALUE = SOME_OTHER_VALUE
Share and enjoy.
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
Link http://s17.postimg.org/pdftjpl1r/Event.png
I have above two table.I want to display third table using oracle. I know display those data using java,vector and other stuff.But couldn't code correct oracle code.In the above display table shows data which are >=SYSDATE.
I think it is something like this:
select e.event_name,
min(dt.start_date) as start_date,
min(dt.start_date)||'-'||max(dt.end_date) as FromTo
from event e join
date_table dt
on e.e_id = dt.e_id
group by e.event_name;
You may need use to_char() to convert date/times to the right format. You don't specify wht the types are in the data, so it is hard to say what needs conversion.
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 8 years ago.
Improve this question
I am new to databases. And our teacher gave us pretty hard assignment. There are two tables. First table nickname is abilities(of superhero's:) ) and second table name superheros.
We have to select nick of Superhero and his average(medial) range for those who has two abilities?
Image of both tables:
Original here: http://postimg.org/image/85pqbc47n/
I will not give you solution - after all, it's homework and you have to learn something :) But I can give you an advice - try to do one task at a time
first, find those superheroes who has only 2 abilities (actually, you can do this by quering only table with abilities)
second - try to find average range of abilities for all superheroes (here you'll need join)
combine your queries
take a look at join, group by, count and having
Don't feel bad if you can't write it at first attempt, your query is not super easy, but 'm sure you can do this.
You can use HAVING and AVG() for this:
SELECT s.NickName, AVG(a.Range)
FROM abilities a
JOIN superhero s
ON a.ID_SuperHero = s.ID_SuperHero
GROUP BY s.NickName
HAVING COUNT(DISTINCT a.Abilities > 1)