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
 update duplicates??

Author  Topic 

isosceles_kramer
Starting Member

4 Posts

Posted - 2011-01-21 : 10:35:50
Hey forum!

So i have a question that might be really odd or really simple. Not sure exactly.

I'm a junior classic ASP programmer that specializes in content management solutions.

Recently i got a request from a client:
1. she has a site that allows her to create "subpages" for every main page of content. So her main pages are things like "About" and the subpages would consist of things like "mission statement", "history" etc.. each main page can have multiple subpages, see?

2. These main pages act as menu headers and all subpages are sections within that menu.

2. She wants the ability to be able to duplicate one subpage so that it shows up in multiple menus.

ALL THIS WORKS JUST FINE. THIS IS THE EASY PART.

However... during testing i noticed an anomaly that i hadn't considered.

What if she UPDATES one of these pages? It should follow that she has the option to update ALL duplicates she's made as well. This lets her avoid the tedium of going into all the duplicates and making the same edit over and over. With one selection from a dropdown menu, all these duplicates she's made in the past should do the same update.

Make sense?

So here's some deets on what i've got to work with. i can't give detailed specifics as this is a client's site and database and it's sort of confidential. So I'll try to keep it as mum as possible...

Let's call the table SUBPAGES. Here's what it looks like:

SUBPAGES
id (pk - int)
parentPage (varchar(50)) *specifies the "main page" that it relates to - this references a page in a table called "PAGES"
pageName (varchar(250)) *specifies the name of this particular subpage
pageContent (varchar(max)) *specifies the actual pageHTML for this subpage
active (int) *specifies whether the page will show up on the live site or not.

Each duplicate page that is being created has the exact same data in each row with the exception of the primary key (as the primary key builds the URL)

So what i've done is put in a dropdown menu in the update page GUI that lets the user specify whether or not she wants to update all duplicates. If she chooses "yes please!" this is evaluated in the engine (if updateDuplicates = 1 then...) and THIS sql statement runs:

sql="SELECT * from subpages where pageName= '" & title & "' and (parentPage='products' and (parentPage='store' or parentPage='onlineonly'))"


Then it loops through all records found and SHOULD update them.

But it doesn't. I think my SQL statement is bad wrong.. Originally I had it just saying "update all rows where title and content are the same" but that didn't work. It only updated the sub with the parentPage of "products"

It appears as if it's evaluating this sql statement and doing the right thing.. I realize that updating based on a non-PK is seriously lacking integrity but given the size of her site and the differences between her pages, I don't see this as being a huge issue.

I'd prefer not to make major DB changes at this point (because it will cost her more and more the more changes we make) but i'm not opposed to it if it must be done.

Thanks so much! If i'm not clear about anything, please ask and i'll try to explain better.

Cheers!
~Isosceles

hell, even numbers are irrational sometimes..

isosceles_kramer
Starting Member

4 Posts

Posted - 2011-01-21 : 10:37:30
I should also mention that I wrote this CMS for her a few months ago. So I'm very, very familiar with it. not sure if this is important or not.

I also should mention that if AT ALL POSSIBLE I'd prefer not to do something like "delete all/recreate all" since the actual URL of the page is based on the primary key value. (for example: www.clientsite.com/products.asp?sub=24 - where 24 is the primary key and "products.asp" is the "menu header" page.

hell, even numbers are irrational sometimes..
Go to Top of Page

kapilarya
Yak Posting Veteran

86 Posts

Posted - 2011-01-21 : 10:56:20
condition parentPage='products' and (parentPage='store' or parentPage='onlineonly')
will always return false so your select statement will return 0 records


Go to Top of Page

isosceles_kramer
Starting Member

4 Posts

Posted - 2011-01-24 : 11:53:37
quote:
Originally posted by kapilarya

condition parentPage='products' and (parentPage='store' or parentPage='onlineonly')
will always return false so your select statement will return 0 records



Ok. I may sound like an idiot but can we discuss this a little further?

Thanks,
Ella

hell, even numbers are irrational sometimes..
Go to Top of Page

isosceles_kramer
Starting Member

4 Posts

Posted - 2011-01-24 : 12:35:11
quote:
Originally posted by kapilarya

condition parentPage='products' and (parentPage='store' or parentPage='onlineonly')
will always return false so your select statement will return 0 records






oh.. never mind.. I think i see what you're saying. You're saying it's trying to pull something where those conditions are both true.. I'm not sure why i wasn't seeing that but the more i look at it, the more i see that i missed something huge.

Ok. That makes sense.

hell, even numbers are irrational sometimes..
Go to Top of Page
   

- Advertisement -