Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello, Basic problem wit T-SQL

Status
Not open for further replies.

AristoSamar

Programmer
Jan 30, 2006
6
GB
Hello,
My name is Mariusz,
I have been working on a database application using c++, win32api and MS Sql Server 2005Express.

My question is about T-Sql. In one of my tables I have some rows where one field is empty (some fields allow NULLs). The type are smalldatetime or varchar. I need to select these rows where the field is empty but my query doesn't receive anything.

I have used some basic queries like these:

select * from log_user where logout_date = NULL;

or

select * from log_user where logout_date = '';

How should I query to get these rows?

And a second question.
To deal with Sql Server I use OTL4 librtary in my c++ code what allow me to conect to the ODBC.
My application logins to Sql Server using login and password which exist as a user in a database. Having programming before every query I send to the SQL Server I logout and login the user I use to connect to this server because I don't know how to check after what time a user will be logged out automaticly by Sql Server. I couldn't find that settings either in Sql Server 2000 or 2005Express. There is possible that an user working with my program can login to the application (same to the SQL Server) and go to have a luch, and try to use a program again. So, break between queries a user is sending to the SQL Server can be long, and if I wouldn't logout and login the database user before every query my program sends I have a chance that my program will send some query to the Server where a datebase user is already disconected.

I'm not shure I explained that clear enought. If not please let me know I'll try to explain that by other way.

greets and thx by advance for answer.
Mariusz
 
You cannot check to see if a field is EQUAL to null, but you can check to see if it IS null. Here's how...

Code:
select * 
From   log_user 
Where  logout_date [!]is[/!] NULL

You should also look in to the IsNull function and the Coalesce function. Both functions assist you when dealing with NULL in a field.

As to the other issue, I'm not sure. Sorry.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
You cannot check to see if a field is EQUAL to null, but you can check to see if it IS null. Here's how..."

That's not exactly true. Here's how...

Declare @TestNull Table(NumberArea int,NullArea int)
insert into @testnull(NumberArea) Values(1)
insert into @testnull(NumberArea) Values(2)
insert into @testnull(NumberArea) Values(3)
SET ANSI_NULLS off
select * from @TestNull where NullArea = null

Check your results.

Here's a good link on it:

 
Thank You for All your help guys. It is working right now. I should know that, because I remember that I have read about that somewhere in past.
Anyway Thank you very much.

Just wondering now about a second part of my question.
Maybe I'll try to describe that in simply words again...

Your program logins to SQL Server and it sends some query and receives data. Then does nothing for long time and finally try to query SQL Server again without login to the Server. It is possible that during my program is "doing nothing" Sql Server will logout connected user "Where can I set some option like "user auto logout time" or similar? I fixed this problet by logout and login again to the SQL Server before every query I proceed, but it isn't like it should be, I think.

Kind regards again
Mariusz

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top