Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. sql Table Lookup best methods?

sql Table Lookup best methods?

Scheduled Pinned Locked Moved Database
databasesysadmintutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ronhawker
    wrote on last edited by
    #1

    I am looking for a good method to do table lookups in a 2003 SQL database. I am retrieving products from an item table and then want to do value lookups in related tables in the same database like category name, category type, brand name etc. These values are referenced in the item master file by guid links to related tables.I am using a datareader to loop through the Select records and then I am writing results to a tab delimited data file for a data conversion. I am limited to net 1.1 and so can't use the 2.0 executescalar for single lookups. What would be the more efficienct method to use? 'Dim myItemData As New DataReader Dim myItemReader As SqlClient.SqlDataReader Dim myItemCommand As New SqlClient.SqlCommand Dim myConnection = New SqlClient.SqlConnection("server=sql01.xxx") myItemCommand.Connection = myConnection myItemCommand.CommandText = "SELECT ""mf_items"".""item_guid"", ""mf_items"".""item_description"", ""mf_items"".""item_wholesale_price"", ""mf_items"".""item_description_title"",""mf_items"".""item_cd"",""mf_items"".""category_guid"" FROM ""CDB006"".""dbo"".""mf_items"" WHERE ""mf_items"".""item_closed"" = 0 And ""mf_items"".""item_visible"" = 1 AND ""mf_items"".""item_available"" = 1" myItemCommand.Connection.Open() myItemReader = myItemCommand.ExecuteReader() Dim myfileout As StreamWriter myfileout = File.CreateText(Server.MapPath("out.txt")) myfileout.WriteLine("link" & vbTab & "title" & vbTab & "description" & vbTab & "price" & vbTab & "image_link" & vbTab & "category" & vbTab & "id") While myItemReader.Read If myItemReader.Item(4).ToString() > "" And Val(myItemReader.Item(2).ToString) > 0 Then 'what method to to look up for example the category name using the category_quid referenced in the item master 'Write out record for parts file

    Ronhawker

    K 1 Reply Last reply
    0
    • R ronhawker

      I am looking for a good method to do table lookups in a 2003 SQL database. I am retrieving products from an item table and then want to do value lookups in related tables in the same database like category name, category type, brand name etc. These values are referenced in the item master file by guid links to related tables.I am using a datareader to loop through the Select records and then I am writing results to a tab delimited data file for a data conversion. I am limited to net 1.1 and so can't use the 2.0 executescalar for single lookups. What would be the more efficienct method to use? 'Dim myItemData As New DataReader Dim myItemReader As SqlClient.SqlDataReader Dim myItemCommand As New SqlClient.SqlCommand Dim myConnection = New SqlClient.SqlConnection("server=sql01.xxx") myItemCommand.Connection = myConnection myItemCommand.CommandText = "SELECT ""mf_items"".""item_guid"", ""mf_items"".""item_description"", ""mf_items"".""item_wholesale_price"", ""mf_items"".""item_description_title"",""mf_items"".""item_cd"",""mf_items"".""category_guid"" FROM ""CDB006"".""dbo"".""mf_items"" WHERE ""mf_items"".""item_closed"" = 0 And ""mf_items"".""item_visible"" = 1 AND ""mf_items"".""item_available"" = 1" myItemCommand.Connection.Open() myItemReader = myItemCommand.ExecuteReader() Dim myfileout As StreamWriter myfileout = File.CreateText(Server.MapPath("out.txt")) myfileout.WriteLine("link" & vbTab & "title" & vbTab & "description" & vbTab & "price" & vbTab & "image_link" & vbTab & "category" & vbTab & "id") While myItemReader.Read If myItemReader.Item(4).ToString() > "" And Val(myItemReader.Item(2).ToString) > 0 Then 'what method to to look up for example the category name using the category_quid referenced in the item master 'Write out record for parts file

      Ronhawker

      K Offline
      K Offline
      kumarprabhakar74
      wrote on last edited by
      #2

      The simplest way is to use join in sql statement for i.e. select i.itemname, i.categorytype from item i inner join categorytype c on c.categorytype=i.categorytype pass above statement is sqlcommand object. Thanks & Regards Kumar Prabhakar

      abc

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups