Showing posts with label null. Show all posts
Showing posts with label null. Show all posts

Thursday, March 22, 2012

ASP returning null sized field from MS SQL database

We currently have an SQL db running on a web server.
One of these fields is a large(ish) amount of text data up to 400
characters and has been cast variously as varchar, nchar and text
type to overcome a problem. The problem appears to be in retrieving
the data via ASP. I understand that ASP can handle string data of this
size so I am okay there.
When the records are retrieved from the db, the data string length =0.
I know the data is there because I have written a Delphi data manager
which interrogates the db and shows all records and their contents.
So if ASP can handle strings this size and the data is there, why do I
get a data length of zero bytes returned when I interrogate the record
set?
Whichever way I cast this field I get the same result.

I know the code is sound as it works locally through a MS SQL server
on my PS.
Anyone have this problem or know what's causing it? I have logged a
support call with my hosting company, but they haven't replied as yet
and I am stuck on an urgent project.

Any suggestions?

Cheers
GrantGrant Davis (grant@.gbdavis.com) writes:
> We currently have an SQL db running on a web server.
> One of these fields is a large(ish) amount of text data up to 400
> characters and has been cast variously as varchar, nchar and text
> type to overcome a problem. The problem appears to be in retrieving
> the data via ASP. I understand that ASP can handle string data of this
> size so I am okay there.
> When the records are retrieved from the db, the data string length =0.
> I know the data is there because I have written a Delphi data manager
> which interrogates the db and shows all records and their contents.
> So if ASP can handle strings this size and the data is there, why do I
> get a data length of zero bytes returned when I interrogate the record
> set?
> Whichever way I cast this field I get the same result.
> I know the code is sound as it works locally through a MS SQL server
> on my PS.
> Anyone have this problem or know what's causing it? I have logged a
> support call with my hosting company, but they haven't replied as yet
> and I am stuck on an urgent project.
> Any suggestions?

Yes one: Post the relevant pieces of your code. Today it is a beautiful
day here in Stockholm, the sun is shining from blue skies. Nevertheless,
I am completely in the dark about what you are doing.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

ASP Impersonation - null user

Hi, this could be an ASP, IIS or SQL server question so please bear with me!
We have an sql server 2000 machine and our IIS 6 machine running seperately
but on the same domain. I can connect fine to the database without using
impersonation, but when it's enabled I get the error:
"Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection."
I've tried looking into this, and noted suggestions of copying accounts to
the database server machine.. is this really necessary? they're on the same
domain, and that would be lots of hassle as I'm hoping to allow anyone on
the domain access to the pages, with authorisation being ran against the sql
server roles/security groups.
Hope my query makes sense.. for info when I check
System.Security.Principal.WindowsIdentity.GetCurrent().Name I get the
expected result.
cheers for any help,
ChrisNot Me
Was your SQL Server set up with Windows Authentication only?
"Not Me" <Not.Me@.nada.nope.hk.za> wrote in message
news:1166521469.754869@.ucsnew2.ncl.ac.uk...
> Hi, this could be an ASP, IIS or SQL server question so please bear with
> me!
> We have an sql server 2000 machine and our IIS 6 machine running
> seperately but on the same domain. I can connect fine to the database
> without using impersonation, but when it's enabled I get the error:
> "Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection."
> I've tried looking into this, and noted suggestions of copying accounts to
> the database server machine.. is this really necessary? they're on the
> same domain, and that would be lots of hassle as I'm hoping to allow
> anyone on the domain access to the pages, with authorisation being ran
> against the sql server roles/security groups.
> Hope my query makes sense.. for info when I check
> System.Security.Principal.WindowsIdentity.GetCurrent().Name I get the
> expected result.
> cheers for any help,
> Chris
>|||"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:%237eitB2IHHA.1280@.TK2MSFTNGP04.phx.gbl...
> "Not Me" <Not.Me@.nada.nope.hk.za> wrote in message
> news:1166521469.754869@.ucsnew2.ncl.ac.uk...
[vbcol=seagreen]
> Was your SQL Server set up with Windows Authentication only?
Aha, I'll check with the admin... was just reading up on how mixed-mode is
required in some circumstances, is this what you're getting at?
cheers,
Chris|||Yes. you can changed it and re-connict again
"Not Me" <Not.Me@.nada.nope.hk.za> wrote in message
news:1166527936.903888@.ucsnew2.ncl.ac.uk...
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:%237eitB2IHHA.1280@.TK2MSFTNGP04.phx.gbl...
>
> Aha, I'll check with the admin... was just reading up on how mixed-mode is
> required in some circumstances, is this what you're getting at?
> cheers,
> Chris
>
>|||Hmmm, it is already in mixed-mode.
Any other ideas?
cheers,
Chris
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:e1vPDJ2IHHA.4712@.TK2MSFTNGP04.phx.gbl...
> Yes. you can changed it and re-connict again
>
> "Not Me" <Not.Me@.nada.nope.hk.za> wrote in message
> news:1166527936.903888@.ucsnew2.ncl.ac.uk...
>|||http://support.microsoft.com/?kbid=555017
http://www.microsoft.com/technet/pr...ds/default.mspx
"Not Me" <Not.Me@.nada.nope.hk.za> wrote in message
news:1166532551.477926@.ucsnew2.ncl.ac.uk...
> Hmmm, it is already in mixed-mode.
> Any other ideas?
> cheers,
> Chris
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:e1vPDJ2IHHA.4712@.TK2MSFTNGP04.phx.gbl...
>|||"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:eyAiGA3IHHA.3268@.TK2MSFTNGP04.phx.gbl...
> http://support.microsoft.com/?kbid=555017
Is that really necessary? it mentions non-domain web environments? all
servers are on the same domain. Seems lengthy for what I imagine to be a
very simple task.
[vbcol=seagreen]
> http://www.microsoft.com/technet/pr...ds/default.mspx[/vbco
l]
A tad more direction would help, there's hundreds of downloads! (it does
have the latest service pack)
cheers,
Chris

Sunday, March 11, 2012

ASC Result Set with Nulls at the bottom

I have a results set that is sorted on LineNum. Not all items have a
LineNum (some are null). I want my result set to return all items in
ASC LineNum order and then list all items with NULL LineNum at the end
of the results. Any Suggestions?

Thanks.On 25 Jan 2006 12:22:36 -0800, ActiveX wrote:

>I have a results set that is sorted on LineNum. Not all items have a
>LineNum (some are null). I want my result set to return all items in
>ASC LineNum order and then list all items with NULL LineNum at the end
>of the results. Any Suggestions?

Hi ActiveX,

ORDER BY CASE WHEN LineNum IS NULL THEN 1 ELSE 0 END, LineNum

--
Hugo Kornelis, SQL Server MVP

Sunday, February 12, 2012

Are these equivalent?

Are the 2 conditions below equivalent? Thanks
dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
ISNULL(dbo.tblBillingDetail.AuthNo, 0)
DavidThey are semantically equivalent, though the first one may perform better.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"David" <dlchase@.lifetimeinc.com> wrote in message
news:eV3YFkqGGHA.596@.TK2MSFTNGP10.phx.gbl...
Are the 2 conditions below equivalent? Thanks
dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
ISNULL(dbo.tblBillingDetail.AuthNo, 0)
David|||Logically they are, but as far as the optimiser is concerned no. You are
using a function on the column AuthNo so that will negate a s on the
index, you'll get an index scan (possibly) which is like a table scan of the
index.
Tony.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"David" <dlchase@.lifetimeinc.com> wrote in message
news:eV3YFkqGGHA.596@.TK2MSFTNGP10.phx.gbl...
> Are the 2 conditions below equivalent? Thanks
> dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
> ISNULL(dbo.tblBillingDetail.AuthNo, 0)
> David
>|||Almost. :)

> dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
ISNULL(dbo.tblBillingDetail.AuthNo, 0) = 0
ML
http://milambda.blogspot.com/

Are there wild cards for the =

I have a stored procedure where I'd like to be able to say

...
...
...
where FldName='*' if the fieldvalue was passed as null or
where fldName='whatever' if the fieldvalue was passed as non-null.

is this possible? Is there a workaround?Originally posted by DerFarm
I have a stored procedure where I'd like to be able to say

...
...
...
where FldName='*' if the fieldvalue was passed as null or
where fldName='whatever' if the fieldvalue was passed as non-null.

is this possible? Is there a workaround?

try this

... where ( FldName is Null ) or ( FldName = 'whatever' )|||Thanks, but where (fldname is null) will only match if the fldname is null ... not if John is in there.

I think I found the answer in a left join. I can left join the table to itself on the field in question and return only if the proper username is there.

Thanks

Thursday, February 9, 2012

Are NULL Counts reliable?

select count(*) from Table(nolock)
-- 11972198
select count(*) from Table(nolock) where Vh_SummVeh_id is null
-- 11894085
select count(*) from Table(nolock) where Vh_SummVeh_id is not null
-- 9546220
...doesn't quite make sense, the collation of the field is NULL and datatyp
e
is int. The entire table has 11972198 records.
also one would think that the below:
select count(*) from Table(nolock) where Vh_SummVeh_id <> null
-- 0
would ave been the same as:
select count(*) from Table(nolock) where Vh_SummVeh_id is not null
-- 9546220
Are Null counts reliable?> [snip]
> ...doesn't quite make sense, the collation of the field is NULL and dataty
pe
> int. The entire table has 11972198 records.
Why did you use NOLOCK here? If the table is being updated then that
may explain the inconsistent results. If not I suggest you try running
DBCC CHECKTABLE.

> select count(*) from Table(nolock) where Vh_SummVeh_id <> null
> -- 0
This is perfectly correct. "<> NULL" returns an UNKNOWN result in every
case. Lookup the basics on NULLs and three-value logic in Books Online.
David Portas
SQL Server MVP
--|||Thanks but the table is not being updated so I shouldn't have had nolocks.
So it still doesn't make sense even after looking at DBCC CHECKTABLE
('TableName') which basically tells me that 'there are 11972198 rows in
800038 pages for object 'TableName''
I need to use a filterwithin a program on this particular field being NULL
so it wont be too good if I cannot rely on the output? Any more ideas?|||marcms
The difference between ANSI sql standard and sql server
SELECT WHERE SALARAY = NULL -- WRONG IN ANSI
SELECT WHERE SALARAY IS NULL-- RIGHT IN ANSI
SO IS
SELECT WHERE SALARAY <> NULL -- WRONG IN ANSI
SELECT WHERE SALARAY IS NOT NULL-- RIGHT IN ANSI
but for update
In ansi sql you have to use = null only
however sql server accepts when you set
SET ANSI_NULLS OFF then null = null
Regards
R.D
--Knowledge gets doubled when shared
"marcmc" wrote:

> Thanks but the table is not being updated so I shouldn't have had nolocks.
> So it still doesn't make sense even after looking at DBCC CHECKTABLE
> ('TableName') which basically tells me that 'there are 11972198 rows in
> 800038 pages for object 'TableName''
> I need to use a filterwithin a program on this particular field being NULL
> so it wont be too good if I cannot rely on the output? Any more ideas?
>|||thanks, I checked that and still no joy.
Is it possible that if stats on 'TableName' were not recently updated, it
could cause this issue?
Also how can I see what the ansi nulls property is set to currently?
This one is weird, don't you think. Personally I have never seen it before!|||yup. It may statistics problem. Update statistics
Regards
R.D
--Knowledge gets doubled when shared
"marcmc" wrote:
> thanks, I checked that and still no joy.
> Is it possible that if stats on 'TableName' were not recently updated, it
> could cause this issue?
> Also how can I see what the ansi nulls property is set to currently?
> This one is weird, don't you think. Personally I have never seen it before![/color
]|||No. It isn't statistics or fragmentation either!!!
Now I really am stumped.
My simple premise was that if you have 10million records from a count(*)
& 6million from a count(*) where Col1 IS NULL the you should get 4million
where Col1 IS NOT NULL.
Makes good enough sense to me. Any other ideas?|||You definitely should try the queries again without the nolock hint. If you
still have inconsistent
results, I would lean towards some corruption in the index used to drive the
query. You could check
the execution plans and see if forcing a table scan give different result. A
bug in SQL Server is
possible as well, of course.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:DDDE7B7C-234B-429E-9AA7-9B8DABC80399@.microsoft.com...
> No. It isn't statistics or fragmentation either!!!
> Now I really am stumped.
> My simple premise was that if you have 10million records from a count(*)
> & 6million from a count(*) where Col1 IS NULL the you should get 4million
> where Col1 IS NOT NULL.
> Makes good enough sense to me. Any other ideas?
>|||YUP. That should be the case.
To make pukka yourself try selecting records instead of count(*)-- Kludge
and compare two queries. and check.. funny. Something is better than nothing
.
But dont say nothing is better than nonsense.
--
Regards
R.D
--Knowledge gets doubled when shared
"marcmc" wrote:

> No. It isn't statistics or fragmentation either!!!
> Now I really am stumped.
> My simple premise was that if you have 10million records from a count(*)
> & 6million from a count(*) where Col1 IS NULL the you should get 4million
> where Col1 IS NOT NULL.
> Makes good enough sense to me. Any other ideas?
>|||Thank for your efforts guys, I am still working on this. Another point of
note is I have already inserted thses NULLS earlier when I created the colum
n
but I have also inserted additional NULLS as I have run a program that does
a
named insert into TableName through a cursor and I have added the value NULL
on each iteration. Could this have an impact? The maximum number or times
this cursor has inserted was 3000 records.
Aside: here is the spHelp on the Col1 in my Filter that checks the number of
NULLS I have...
Col_name Type Computed Length Prec Scale Nullable TrimTrBlanks
FixedLenNullInSource Collation
-- -- -- -- -- -- --
-- -- --
Col1 int no 4 10 0 yes (n/a)
(n/a) NULL
I have to admit I am getting a bit desperate now but appreciate all your
inputs