Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to display two sets of fields in the same recordset?

Status
Not open for further replies.

cactus1000

Programmer
Aug 31, 2001
149
US
Here's my problem -- All users who fill out my web form are required to give their name, but they can choose to remain anonymous to people searching the database (but not to the db administrator).

So, if a user decides to view all records from the database, I need a recordset where "anonymous" records display all fields except name, and other records display all fields.

Can I do this in a single recordset? I don't know SQL well enough to figure this out.
 
Various ways you could probably do this.
One way being that the DB admin logs into the system then you have a small routine to build the sql

If adminloggedin=true then sql1="name, "

sql2="select address, id, etc.." & sql1 & " where etc...

hope i made that clear Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
It isn't just the admin who gets to see the names -- the users need to see the names for some records, but not for others.

I know I could just write two different queries and have two different click buttons; "view anonymous postings" and "view signed postings" -- but I'd really like to have them both in the same recordset.
 
I am assuming there is some sort of flag in the records that determine whether they are anonymous or not. Just select from the table, irregardless of whether the data is from anonymous or non-anonymous people. Then when you go to display the record just do an if check on that field and if they are supposed to be anonymous then output anonymous, otherwise output the name from the recordset.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
If you are using SQL Server and you have a bit column for anonymous:

Code:
CREATE TABLE test1 (
	nameID INT IDENTITY,
	fullName varchar(10),
	viewable BIT DEFAULT (0)
)
INSERT INTO test1 VALUES('Mike',1)
INSERT INTO test1 VALUES('Hidden',0)
INSERT INTO test1 VALUES('Joe',1)
INSERT INTO test1 VALUES('Gina',1)

SELECT CASE viewable
	when 1 then fullname
	else 'Anon'
END
FROM test1
 
Hi Cactus,

You can create an additional column called "Anon" and give it a tinyint value.. if the user wants to be ANONYMOUS, then fill that column with a 1, if not fill it with a 0. Then when you go to display the information on screen, if the ANON value is 1 then you don't display the name of the person (except for the Admin).

Cheers,

G.
 
An easier way to do this, depending on size constraints, would be to duplicate the name field. Name the second one a different name, and populate with a name if they allow it, with a generic "anonymous" if they don't. Then if anyone other than the DB logs in you select against the second field which will have a value. If the DB logs in he gets different SQL statement and see's thename. The money's gone, the brain is shot.....but the liquor we still got.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top