Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1055143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:31:05+00:00 2026-05-16T17:31:05+00:00

I grabbed a bunch of SQL IDs I need to update with Python and

  • 0

I grabbed a bunch of SQL IDs I need to update with Python and PyODBC:

import pyodbc
cnxn = pyodbc.connect('DSN=YesOne;PWD=xxx')
cursor = cnxn.cursor()
cursor.execute("SELECT ID FROM One.dbo.Two WHERE STATUS = 'OnGoing' AND ID = ''")

I have a second bit of code that updates the IDs:

cursor.execute("Update One.dbo.Two SET STATUS = 'Completed', Modified = 'Today' WHERE ID = '1051'")

The problem is when I view the IDs grabbed in Python earlier I get either:

row = cursor.fetchall()
f row:
    print row

[(1016, ), (1017, ), (1019, ), (1020,
), (1021, ), (1025, ), (1026, ),
(1027, ), (1029, ), (1048, ), (1049,
)]

or

if row:
    print row[3]

(1020, )

I need just the number so I can run my second part of the script for the:

WHERE ID = '1051'"

part. I tried with:

count = len(row)
while count > 0:
    newrow = row[count-1]
    print 'SELECT ID FROM One.dbo.Two WHERE ID = ' + str(newrow)
    count = count-1

and it gave me:

SELECT ID FROM One.dbo.Two WHERE ID = (1049, )
SELECT ID FROM One.dbo.Two WHERE ID = (1048, )
etc…

And I tried:

str(row[1]).lstrip('(),')

and I got:

‘1017, )’

How do I strip the characters from the ID so I can reuse the ID?

Thanks,

Adrian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:31:06+00:00Added an answer on May 16, 2026 at 5:31 pm

    First of all:

    rows = [x[0] for x in cursor.fetchall()]
    

    Then abandon your terrible while loop:

    for row in rows:
      print 'SELECT ID FROM One.dbo.Two WHERE ID = %s' % row
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to change what rows are grabbed from the database based upon a
I need to convert bitmapData grabbed from movie clip to jpeg or png. Is
using PHP and MySQL i have grabbed an array of facebook user ids from
I have a website with lot of content which is being grabbed from sql
I grabbed this code form JCarousel and just trying to understand these lines below.
I grabbed firefox 3.7a (note go to about:config and enable webgl) and ran the
I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
I have a JavaScript variable I grabbed from a form field and I am
I'm working on a long string grabbed from a Session that uses § (Section
I am trying to compare a value which was grabbed using the get method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.