Hurry! Query Need help.

M

manmit.walia

Hello Fellow Developers,
I am very new to SQL and ASP.net and in the learning process. I have to
do a small web application that handles documents stored on a sql
database. The requirements of the functionality of the application are
below. I am just having trouble setting my query to work correctly.

Problem:
I want to be able to pull documents and folders that have the same
ClientID. However, here is the catch, the query should take two inputs
- ClientID and ParentID (which is an ID representing FolderID from the
Folder Table; the document/folder does not belong to another folder
then the system will enter ZERO as the ParentID). I hope this is
clear???

Any help is greatly appreciated, as life is a learning experience.

Database Structure:

Table Name: Client
Fields:
ClientID primary key autonumber
Name nvarchar 255

Table Name: ClientDocs
Fields:
DocID primary key autonumber
Document image (the actually file in bytes)
FriendlyName nvarchar 255
ClientID foreign key -> [Table Client]
ClientFolderID foreign key -> [Table ClientFolders]

Table Name: Folders
Fields:
FolderID primarykey autonumber
FolderName nvarchar 255

Table Name: ClientFolder
Fields:
ClientFolderID primarykey autonumber
FolderID foreign key -> [Table Folders]
ParentID int
ClientID foreign key -> [Table Clients]
 
T

tfsmag

you should do it in a conditional statement. You can do it in either
your programming code or in your SQL code. For instance whatever is
passing your parameters (clientid,parentid) to the query should have a
condition applied to it that if the parameter for parentid is null, is
empty, or is equal to 0, then the parameter is set to 0. Otherwise pass
along the parameter as usual. As for the SQL code I would do it like
this.

SELECT * FROM Client WHERE ClientID='parameter for client id here' AND
ParentID='parameter for parent id here'

Or am I missing something here?
 
T

tfsmag

bah i should have looked closer... it's definitely possible but will
take me a bit of time to do. If I have time tomorrow morning I'll try
to help you sort it out.
you should do it in a conditional statement. You can do it in either
your programming code or in your SQL code. For instance whatever is
passing your parameters (clientid,parentid) to the query should have a
condition applied to it that if the parameter for parentid is null, is
empty, or is equal to 0, then the parameter is set to 0. Otherwise pass
along the parameter as usual. As for the SQL code I would do it like
this.

SELECT * FROM Client WHERE ClientID='parameter for client id here' AND
ParentID='parameter for parent id here'

Or am I missing something here?

Hello Fellow Developers,
I am very new to SQL and ASP.net and in the learning process. I have to
do a small web application that handles documents stored on a sql
database. The requirements of the functionality of the application are
below. I am just having trouble setting my query to work correctly.

Problem:
I want to be able to pull documents and folders that have the same
ClientID. However, here is the catch, the query should take two inputs
- ClientID and ParentID (which is an ID representing FolderID from the
Folder Table; the document/folder does not belong to another folder
then the system will enter ZERO as the ParentID). I hope this is
clear???

Any help is greatly appreciated, as life is a learning experience.

Database Structure:

Table Name: Client
Fields:
ClientID primary key autonumber
Name nvarchar 255

Table Name: ClientDocs
Fields:
DocID primary key autonumber
Document image (the actually file in bytes)
FriendlyName nvarchar 255
ClientID foreign key -> [Table Client]
ClientFolderID foreign key -> [Table ClientFolders]

Table Name: Folders
Fields:
FolderID primarykey autonumber
FolderName nvarchar 255

Table Name: ClientFolder
Fields:
ClientFolderID primarykey autonumber
FolderID foreign key -> [Table Folders]
ParentID int
ClientID foreign key -> [Table Clients]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top