Solved

Design Question!

Posted on 2011-09-12
4
215 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

911 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

19 Experts available now in Live!

Get 1:1 Help Now