473,765 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select statement help

I have created a script that runs once a week and copies data from one
table (phpbb_users is the actual table name) in a database called
users

I have a table called users. There are two tables in this database.
The table names are:

phpbb_users
phpbb_users_bac kup

The two tables have identical structures. I made phpbb_users_bac kup a
duplicate structure of phpbb_users. Then I wrote a script that runs
once a week and loads that 2nd table phpbb_users_bac kup with the data
from phpbb_users. I just dump the data from phpbb_users and load it
into phpbb_users_bac kup. A few minutes after that happens on that day
once a week I run a script that does a compare of the two tables and
outputs it to a file. The output file displays about 23 columns out of
40 and shows me all data even nulls that are in the columns.

The issue I have:

There are 23 columns in each record. Each record that appears in that
output file has one or more columns that have been changed. What I
need to do is display only the username column whether it changes or
not and all other columns that were changed or different need to be
displayed as well. In other words I need to always see the username
column in the output file and only columns that were changed/different
from one table to the other. Example, if a column named
user_last_name changes in phpbb_users I want to see that
user_last_name and username column displayed in my output file only
and not the other 21 columns of data that did not change on that
record.

I have the sql I use to run the comparison. If anyone needs more info
please post it here or email me directly at rk******@online acc.com.

SELECT
t2.username, t1.user_last_na me, t2.user_first_n ame, t2.user_email,
t2.user_company , t2.user_address , t2.user_city, t2.user_state,
t2.user_zip, t2.user_work_ph one, t2.user_work_fa x, t2.user_cellula r,
t2.user_pager, t2.user_prop_lo ca_muni, t2.user_prop_lo ca_muni2,
t2.user_prop_lo ca_muni3, t2.user_prop_lo ca_muni4,
t2.user_prop_lo ca_muni5, t2.user_prop_lo ca_muni6,
t2.user_prop_lo ca_county, t2.user_prop_lo ca_county2,
t2.user_prop_lo ca_county3, t2.user_prop_lo ca_county4,
t2.user_prop_lo ca_county5, t2.user_prop_lo ca_county6, t2.user_website ,
t2.user_from
FROM
phpbb_users_bac kup AS t1 RIGHT OUTER JOIN
phpbb_users AS t2 ON ((t1.user_id=t2 .user_id) AND
(t1.username=t2 .username) AND (t1.user_email= t2.user_email OR
(t1.user_email IS NULL AND t2.user_email IS NULL)) AND
(t1.user_compan y=t2.user_compa ny OR (t1.user_compan y IS NULL AND
t2.user_company IS NULL)) AND (t1.user_city=t 2.user_city OR
(t1.user_city IS NULL AND t2.user_city IS NULL)) AND
(t1.user_zip=t2 .user_zip OR (t1.user_zip IS NULL AND t2.user_zip IS
NULL)) AND (t1.user_phone= t2.user_phone OR (t1.user_phone IS NULL AND
t2.user_phone IS NULL)) AND (t1.user_fax=t2 .user_fax OR (t1.user_fax
IS NULL AND t2.user_fax IS NULL)) AND
(t1.user_prop_l oca_muni=t2.use r_prop_loca_mun i OR
(t1.user_prop_l oca_muni IS NULL AND t2.user_prop_lo ca_muni IS NULL))
AND (t1.user_prop_l oca_muni2=t2.us er_prop_loca_mu ni2 OR
(t1.user_prop_l oca_muni2 IS NULL AND t2.user_prop_lo ca_muni2 IS NULL))
AND (t1.user_prop_l oca_muni3=t2.us er_prop_loca_mu ni3 OR
(t1.user_prop_l oca_muni3 IS NULL AND t2.user_prop_lo ca_muni3 IS NULL))
AND (t1.user_prop_l oca_muni4=t2.us er_prop_loca_mu ni4 OR
(t1.user_prop_l oca_muni4 IS NULL AND t2.user_prop_lo ca_muni4 IS NULL))
AND (t1.user_prop_l oca_muni5=t2.us er_prop_loca_mu ni5 OR
(t1.user_prop_l oca_muni5 IS NULL AND t2.user_prop_lo ca_muni5 IS NULL))
AND (t1.user_prop_l oca_muni6=t2.us er_prop_loca_mu ni6 OR
(t1.user_prop_l oca_muni6 IS NULL AND t2.user_prop_lo ca_muni6 IS NULL))
AND (t1.user_prop_l oca_county=t2.u ser_prop_loca_c ounty OR
(t1.user_prop_l oca_county IS NULL AND t2.user_prop_lo ca_county IS
NULL)) AND (t1.user_prop_l oca_county2=t2. user_prop_loca_ county2 OR
(t1.user_prop_l oca_county2 IS NULL AND t2.user_prop_lo ca_county2 IS
NULL)) AND (t1.user_prop_l oca_county3=t2. user_prop_loca_ county3 OR
(t1.user_prop_l oca_county3 IS NULL AND t2.user_prop_lo ca_county3 IS
NULL)) AND (t1.user_prop_l oca_county4=t2. user_prop_loca_ county4 OR
(t1.user_prop_l oca_county4 IS NULL AND t2.user_prop_lo ca_county4 IS
NULL)) AND (t1.user_prop_l oca_county5=t2. user_prop_loca_ county5 OR
(t1.user_prop_l oca_county5 IS NULL AND t2.user_prop_lo ca_county5 IS
NULL)) AND (t1.user_prop_l oca_county6=t2. user_prop_loca_ county6 OR
(t1.user_prop_l oca_county6 IS NULL AND t2.user_prop_lo ca_county6 IS
NULL)) AND (t1.user_member _no=t2.user_mem ber_no OR (t1.user_member _no
IS NULL AND t2.user_member_ no IS NULL)) AND
(t1.user_websit e=t2.user_websi te OR (t1.user_websit e IS NULL AND
t2.user_website IS NULL)) AND (t1.user_gender =t2.user_gender ) AND
(t1.user_work_p hone=t2.user_wo rk_phone OR (t1.user_work_p hone IS NULL
AND t2.user_work_ph one IS NULL)) AND
(t1.user_work_f ax=t2.user_work _fax OR (t1.user_work_f ax IS NULL AND
t2.user_work_fa x IS NULL)) AND (t1.user_cellul ar=t2.user_cell ular OR
(t1.user_cellul ar IS NULL AND t2.user_cellula r IS NULL)) AND
(t1.user_pager= t2.user_pager OR (t1.user_pager IS NULL AND
t2.user_pager IS NULL)) AND (t1.user_addres s=t2.user_addre ss OR
(t1.user_addres s IS NULL AND t2.user_address IS NULL)) AND
(t1.user_first_ name=t2.user_fi rst_name OR (t1.user_first_ name IS NULL
AND t2.user_first_n ame IS NULL)) AND
(t1.user_last_n ame=t2.user_las t_name OR (t1.user_last_n ame IS NULL AND
t2.user_last_na me IS NULL)) AND (t1.user_state= t2.user_state OR
(t1.user_state IS NULL AND t2.user_state IS NULL)) AND
(t1.user_realna me=t2.user_real name) AND
(t1.user_home_p hone=t2.user_ho me_phone OR (t1.user_home_p hone IS NULL
AND t2.user_home_ph one IS NULL)) AND
(t1.user_home_f ax=t2.user_home _fax OR (t1.user_home_f ax IS NULL AND
t2.user_home_fa x IS NULL)))
WHERE
t1.user_birthda y IS NULL;
Another thing I would love to do is if the column is NULL for any of
the 22 columns (username is never null) I do not want to display the
word NULL. I would rather it be blank. In the event that a column is
changed from an actual last_name to nothing in that field then I do
not want to show NULL I would rather it be left blank.

Robert Knowles
rk******@online acc.com
Jul 20 '05 #1
0 1285

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3844
by: jayson_13 | last post by:
Hi, I need to implement a counter and i face problem of locking so hope that u guys can help me. I try to do test like this : 1st connection SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update; (when i execute this statement and i guess that this will lock the
2
6389
by: Edwinah63 | last post by:
Hi Everyone, All the very best for 2004!! i need urgent help with this problem, the users are about to skin me alive!! we have an access front end with linked to sql server 2k tables. when a user tries to insert a record into one of the tables it
1
4480
by: brett | last post by:
Here is my SQL string: "SELECT to_ordnum, to_orddate," _ & "(SELECT SUM((DDPROD.pr_stanmat * DDPROD.pr_prfact) * (DOBOM2.b2_quant * DDORD.or_quant)) FROM DDPROD INNER JOIN DOBOM2 ON DDPROD.pr_prodnum = DOBOM2.b2_prodnum INNER JOIN DDORD ON DOBOM2.b2_orid = DDORD.or_id INNER JOIN DDTORD ON DDORD.OR_TOID = DDTORD.TO_ID WHERE DOBOM2.b2_ordnum = ''order number here from result of outer select) AS Total" _ & "FROM DDTORD WHERE to_trak2id IN...
3
5727
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int pointing to the sentence they come from (a column called "regret"). I also have a table of stop words (called "GenericStopWords") that contains the words I do not want to consider. That table has a single column called "word". I started off using a...
7
11914
by: CharlesEF | last post by:
Hi All, I have run into another problem that is eating my lunch. Should be simple but I am having one heck of a time. Please look at this SELECT statement: SELECT FROM States WHERE ] = "US"; is the SQL column name (because it sarts with 2?). As the statement is shown I get the error message: Unclosed quotation mark before the character
2
1585
by: GIS Analyst | last post by:
Hi to all I wish to be able to have a standard select statement which has additional fields added to it at run-time based on supplied parameter(s). ie declare @theTest1 nvarchar(10) set @theTest1='TRUE'
12
7697
by: TP | last post by:
Here is my problem. I need to display a table about which I have no information except the table name. Using metadata I can somehow show the column names and record values. But my table has 1 million rows and if I do a select * then I do get 1 million rows. I want to be able to provide page navigation as google does, page
3
6472
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
5
6898
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has the described properties. If I use the same statement in a select into statement (see the second select) I get several datasets with the described properties like I didn't use distinct
2
3413
by: kxyz | last post by:
Hello everyone, I need help with a stored procedure or two. My stored procedures are supposed to check if a certain record exists. If it does exist, then I select everything from that row, as well as a value for the exit status of the SP. If the record doesn't exist, it selects an error message as the exit status. I've recreated the SP (while changing field names) and restructured the table, just to get straight to the point.
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9955
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.