Archive for the ‘sql statement’ Category

How do i write a SQL statement with regular expression that cleans "-" and excess spaces from a number field ?

December 24, 2009 - 9:51 pm 1 Comment

i have a number field that needs cleaning up, for example
1) need to remove dash "-"
2) remove excess spaces in between numbers
3) prefix with some numbers if the length does not meet minimum length
4) remove text if found in the number field.

any help would be appreciated as i am nuts with sql..

1) use replace function
Update home Set address =replace(address,’-',”) From home where address like ‘%-%’

2) replace can work as well
select address , replace(address,’ ‘,”) From home where address like ‘% %’

3) sample:
declare

What 2 componenets are needed to write an SQL statement?

November 5, 2009 - 11:12 pm 6 Comments

How do you sum the columns

Main are
Step 1: Loading Drivers
Step 2: Making a Connection
Step 3: Creating JDBC Statements
Step 4: Executing the Statement
Step 5: Looping Through the ResultSet
Step 6: Closing the Connection and Statement Objects
For details of each step go to this link
http://www.developer.com/db/article.php/942641

SQL statement?

November 3, 2009 - 8:54 am 2 Comments

I have column name "PROCESS" and "USER" with same table.PROCESS has process1,process2,process3……process100 and every process has a different user but not all users has the access in every process there are only some..
Question: how can i create a statement that i can only view all users that can access all the processes???
any suggestion or comments is highly appreciated.
a big thanks..

mel
e.g.
table name: Table
Column: PROCESS, USER

PROCESS USER
process1 A
e.g.
table name: Table
Column: PROCESS, USER

PROCESS USER
process1 A
B
C
process2 D
E
C
process3 F
G
H
C
process4 I
C
J
K
:
:
:
process100 L
M
Z
C
users are A,B,C,D,E,F,J……….Z
process are process1, process2…..Process100
which user has the access on all the processes???

http://answers.yahoo.com/question/index?qid=20070110195245AA0tYW6

How do I create a join SQL statement?

October 31, 2009 - 9:17 pm 2 Comments

I need to provide a join sql statement that returns a store ID, store name, manager employee first and last name fields, manager employee grade, the city and state fields.

..i’m not sure of this.. you’re joining 2 or more tables in here?

and.. what’s you’re application? where will you use it? access?

what are the fields in the table1, and what are the fields in table2 … that you’ll want to join…

if i have these tables with their fields (e.g.)

Table name: Weather table
Fields: City, Temperature, Date

Table name: State table
Fields: State, City

SELECT Weather.City, Weather.Temperature, Weather.Date, State.State
FROM Weather INNER JOIN State
ON Weather.City = State.City

the result:

Table name: Weather
Fields: City, Temperature, Date, State

…don’t know if this can help you….

I want to create sql statement to find delta values in time series.?

October 21, 2009 - 10:19 am 3 Comments

I have a table with two fields timestamp and value. new values are added to the table every 15min. i want to find the change in value from one record to the next. how do i do this using sql.

It always helps if you could specify what database you use. Anyway, I’ll assume you use Oracle. You can use the power of analytic functions in Oracle to accomplish your goal.

Study the following example carefully. It shows how the "lag" analytic function can be used effectively to find out sliding-window differences in a single-pass through the table.

===================================================
test@ORA10G>
test@ORA10G> –
test@ORA10G> alter session set
2 nls_date_format = ‘dd-Mon-yyyy hh:mi:ss AM’;

Session altered.

test@ORA10G> select * from t;

TSTAMP VALUE
———————– ———-
01-Jan-2009 08:00:00 AM 23.5
01-Jan-2009 08:15:00 AM 28.8
01-Jan-2009 08:30:00 AM 33.1
01-Jan-2009 08:45:00 AM 49.9
01-Jan-2009 09:00:00 AM 55.8
01-Jan-2009 09:15:00 AM 19.6
01-Jan-2009 09:30:00 AM 20.3
01-Jan-2009 09:45:00 AM 66.2
01-Jan-2009 10:00:00 AM 64.7

9 rows selected.

test@ORA10G> –
test@ORA10G> select tstamp,
2 value,
3 lag (value) over (order by tstamp) lag,
4 value - lag (value) over (order by tstamp) diff
5 from t;

TSTAMP VALUE LAG DIFF
———————– ———- ———- ———-
01-Jan-2009 08:00:00 AM 23.5
01-Jan-2009 08:15:00 AM 28.8 23.5 5.3
01-Jan-2009 08:30:00 AM 33.1 28.8 4.3
01-Jan-2009 08:45:00 AM 49.9 33.1 16.8
01-Jan-2009 09:00:00 AM 55.8 49.9 5.9
01-Jan-2009 09:15:00 AM 19.6 55.8 -36.2
01-Jan-2009 09:30:00 AM 20.3 19.6 .7
01-Jan-2009 09:45:00 AM 66.2 20.3 45.9
01-Jan-2009 10:00:00 AM 64.7 66.2 -1.5

9 rows selected.

test@ORA10G>
test@ORA10G>
===================================================

I used Oracle 10g. Analytic functions were introduced in Oracle 8i. For versions older than that, you’d have to join the table with itself, which would result in multiple passes through the same table. Use of analytic functions result in much more efficient queries.

HTH,
techieguy

How do your write a SQL statement to return the emails that show up more than once in a table?

October 19, 2009 - 11:12 am 1 Comment

I’m just working with the schema:
Email varchar(100)
City varchar(100)
State char(2)

I think it would be like this. Hope it helps!

SELECT email,
COUNT(email) AS NumOccurrences
FROM (table name)
GROUP BY email
HAVING ( COUNT(email) > 1 )

How do your write a SQL statement to return the emails that show up more than once in a table?

October 19, 2009 - 11:12 am 1 Comment

I’m just working with the schema:
Email varchar(100)
City varchar(100)
State char(2)

I think it would be like this. Hope it helps!

SELECT email,
COUNT(email) AS NumOccurrences
FROM (table name)
GROUP BY email
HAVING ( COUNT(email) > 1 )

How to write an SQL statement with a where clause but there is a data type miss match?

October 17, 2009 - 8:21 am 6 Comments

The SQL string looks like this :
"Select * from Test2 where PROVIDER_ID = ‘" & LogInfo.Provider_ID & "’"

i want to only select the info that matches up the provider_id. The problem is that the PROVIDER_ID in the database is a datatype number and cant be changed because it will mess up the relatioships in the database. I think the equals sign is the problem cause it’s doing a math operation and not the compare. Is there any way around this. The login.provider_id is a string that is in a class that saves the provider_id i want to look up

Not sure of it but try "like" instead of "="

can you write an sql statement for a datagrid?

October 5, 2009 - 3:59 pm 2 Comments

Ok,this might sound stupid tho…but can you write an sql statement for a datagrid?

e.g. select * from Datagrid1

no i cannot

How do i select all the fields, and the count of 1 field in one sql statement?

October 3, 2009 - 6:10 am 3 Comments

<SELECT COUNT (employee_id), * FROM EMPLOYEES> does not work. PLEEEASE HELP ME!!!!!
<SELECT COUNT (employee_id) AS employee_count, * FROM EMPLOYEES> does not work either

Rowcount instead of count.