Solved

Design Question!

Posted on 2011-09-12
4
219 Views
Last Modified: 2012-05-12

I have two tables:

LLocation (LenderId RegionId StateId CityTypeId)

LCity (LenderId CityId)

Each lender will be there in different regions,
inside region there will be state,
inside state there will be citytypes,
inside citytype there wil be cities
one lender will have only one city

RegionId,StateId,CityTypeId will be inserted the value null.
if all region or all state or all citytype selected

I need a sql query which to

insert and update into these two tables

and a query to

search based on LenderId RegionId StateId CityTypeId
where  Lenderid RegionId CityTypeId  are dropdown
and StateId  will have a text box value


Note: If the Null in a column , means all so just i need to show one
      row have null "all" not the sub values that comes under "all"
 
0
Comment
Question by:PeteEngineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
ID: 36523407
insert into LLocation (LenderId) values(@LenderID);

update LLocation set
  RegionId =@RegionId
  StateId =@StateId
  CityTypeId=@CityTypeId
where LenderId=@LenderID);
0
 
LVL 42

Expert Comment

by:dqmq
ID: 36523558
Wow..I don't know where to begin.  Please, please take a deep breath, slow down, and get some assistance with your table design, your understanding of nulls, and better express your requirements.  You are not ready to formulate queries.

Just to illustrate a couple "issues" that pop out:
1. Each lender can be in different regions, thus different states. thus different cities. But, one lender will have only one city??????

2. "Inside state there will be city types".  Are you sure?  I can only guess what a city type is, but NONE of my guesses would have city type within state.  Are you saying two states cannot have the same city type?  Or or you just describing one way of drilling down to a city of interest?  

3.  You do not have data that shows which state a city is in or which city-type describes a city.



 
   
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 36523618
one lender will have only one city?????? yes
 "Inside state there will be city types".  Are you sure? no
Are you saying two states cannot have the same city type? Yes



0
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 36523964
If a lender can only have one city.  And that city belongs to a city type which in turn belongs to a state which in turn belongs to a region, then the lender can have at most one region.  Do you see my confusion?

Also, you then have one table that shows city for a lendor and another that shows location for a lendor.  But city IS a location, so that's very confusing, too.  There is no relationship that shows a city's type, except the one that is implied by the lendor assignments.

Let me ask this.  If you assign a lendor to a city, does not the city determine the city type and the state and the region?    
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question