Python Forum
cursor.execute: How to insert dynamic number in a string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cursor.execute: How to insert dynamic number in a string?
Thumbs Up 
Thank you @buran !
Your hint does the trick! Problem solved.
My altered source code for people who want to know the solution:

# ^^^^^^^^^^^^^^^^^^^
# "Artikelnummer" as a string
conn = pymssql.connect(server="server" , user="mustermann", password="passwort")
cursor = conn.cursor()
cursor.execute("""SELECT convert(NVARCHAR,b.[Posting Date],104) as Datum
	   ,b.[Posting Date]
	   ,a.[No_] as Artikel#
	    ,b.[Document No_]
		,b.[Entry Type]
		,"Vorgang" =
	      when [Entry Type]=0 then 'Einkauf'
		  when [Entry Type]=1 then 'Verkauf'
		  when [Entry Type]=2 then 'Zugang'
		  when [Entry Type]=3 then 'Abgang'
		  when [Entry Type]=4 then 'Umlagerung'
		  when [Entry Type]=5 then 'Verbrauch'
		  when [Entry Type]=6 then 'Istmeldung'
		  when [Entry Type]=7 then 'N.N'
		  when [Entry Type]=8 then 'Verbrauch für Montage'
		  when [Entry Type]=9 then 'Montage-Istmeldung'
		,cast(round(b.[Quantity],2,2) as real) as Menge
      ,[Base Unit of Measure]
      ,cast(round([Unit Cost],2) as real) as 'EuroProEinheit'
      ,cast(round([Lot Size],2,2) as real) as Losgröße
      ,cast(round([Safety Stock Quantity],2,2)as real) as Sich_Bestand     
      ,[Blocked Purchase]
FROM [Mustermann].[dbo].[Mustermann_GmbH$Item] as a
   LEFT JOIN [Mustermann].[dbo].[Mustermann_GmbH$Item Ledger Entry] AS b ON a.No_ = b.[Item No_]
   LEFT JOIN [Mustermann].[dbo].[Mustermann_GmbH$Vendor] as Lieferant on a.[Vendor No_] = Lieferant.No_
   where a.No_ like %s""", Artikelnummer)
#                   ^^     ^^^^^^^^^^^^^
#  format and the variable Artikelnummer again

Messages In This Thread
[solved] RE: cursor.execute: How to insert dynamic number in a string? - by stoeberhai - Mar-18-2021, 12:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  loop for dynamic cut string - cleaner way? korenron 4 416 Nov-22-2021, 02:30 PM
Last Post: korenron
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 1,925 May-02-2021, 03:45 PM
Last Post: Anldra12
  Regular expression: cannot find 1st number in a string Pavel_47 2 1,050 Jan-15-2021, 04:39 PM
Last Post: bowlofred
  change mouse cursor (in Windows) mgroen 0 533 Nov-11-2020, 11:26 AM
Last Post: mgroen
  Please support regex for version number (digits and dots) from a string Tecuma 4 1,246 Aug-17-2020, 09:59 AM
Last Post: Tecuma
  Make an array of string number in a List polantas 5 1,557 May-27-2020, 07:18 AM
Last Post: buran
  line number of first and second occurance of string in a file mdalireza 1 928 Nov-18-2019, 09:55 AM
Last Post: perfringo
  How can i judge 1st string position is correct number christing 3 1,236 Oct-30-2019, 03:32 AM
Last Post: newbieAuggie2019
  How to avoid slow cursor operations? sevensixtwo 0 1,022 Oct-11-2019, 02:23 PM
Last Post: sevensixtwo
  Trouble retrieving dictionary from mysql.connector cursor swechsler 2 1,508 Sep-17-2019, 05:21 PM
Last Post: swechsler

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020