Solved

Design Question!

Posted on 2011-09-12
4
213 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
  • 2
4 Comments
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now