So you don't know the table names, the primary keys, or ANY of the column names in these tables?????
  ----- Original Message -----
  From: Qasim Rasheed
  To: CF-Talk
  Sent: Monday, August 16, 2004 3:07 PM
  Subject: Re: SQL Question

  Brian,

  Thanks for the nice suggestion but my problem is that there are
  several tables and some of them doesn't have any primary key
  associated with them. A brute force approach that I tried and it
  didn't even worked was to get all database table name from SQL Server
  metadata and then loop through that query and deleting all records
  except top 1. But the problem here is the program doesn't know the
  column name in advance. What I did was to do a temp query and get the
  column names using query.culumnlist and then delete the record as
  follows

  <cfquery name="temp" datasource="#db.dsn#">
  select *
  from #tablename#
  </cfquery>
  <cfquery name="del" datasource="#db.dsn#">
  delete
  from #tablename#
  where #listfirst( temp.columnlist )# not in (select top 1
  #listfirst( temp.columnlist )# from #tablename# )
  </cfquery>

  It works as long as listfirst() returns first column as numeric. I am
  guessing there is a better and more elegant approach to this? I still
  need help :(

  <snip>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to