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

Friday, March 23, 2012

How to test if Index exists?

How can I test if a table already has a specific index present?
Id normally test for an object with: if object_ID('My Object') is null then...
What technique works with an index? Or can you use the object_Id function, how do you reference the index?
Many thanks.You can check if a table has an index at all, not a specific index, unless you want to test for an existance of the name:

if exists (select 1 from dbo.sysindexes where object_name(id)='your_table' and indid between 2 and 254) print 'There is at least 1 non-clustered index'
else print 'No non-clustered indexes found'|||IF INDEXPROPERTY ( OBJECT_ID('your_table') , 'your_table_index' , 'IndexID' ) IS NULL

If you know the name the above should work; I have not tested it.

Tim S|||sp_helpindex tableName

OR

IF EXISTS (SELECT indid
FROM sysindexes
WHERE id = OBJECT_ID('tableName')
AND name = 'indexName') THEN

....sql

Friday, March 9, 2012

How to suppress a field if it is null

I have a report where it displays demographic information. The Address2 field
is sometimes NULL and I haven't found a way to suppress this field. The only
thing I can do is make it invisible/visible with an IIF statement. I know in
Crystal Reports you could check a box that said "SUPPRESS IF BLANK" and this
would move all the other fields up on the report accordingly. With SQL
Reporting services it doesn't adjust the fields underneath it so I have a
blank/empty space. Does anyone know of any other things I can try.
ThanksHi GORAMS,
Are you using a table control? If so, take a look at the actual detail
line for Address2, and make sure that your IIF statement to control
visibility is set on the entire tablerow as opposed to just the
Address2 textbox. Just setting the visibility property on the Address2
textbox would cause your problem if the table has more than column.
Does this help?
Matt A
Rpeorting Services Newsletter at www.reportarchitex.com|||RS is shrinking fields if you specify that it is invisible (for example if
you put in Hidden property "=Fields!Something.Value is Nothing"). But, as in
CR, that depends of other fields in line, so if one is supperesed and other
one is not, it will not move fields under supperesed one up...
You can play arround little with columns maybe, or lists if you want to do
something like that..
Stjepan
"GORAMS" <GORAMS@.discussions.microsoft.com> wrote in message
news:A28602C1-D97C-4A19-9ABD-6A06D6A4A9BA@.microsoft.com...
>I have a report where it displays demographic information. The Address2
>field
> is sometimes NULL and I haven't found a way to suppress this field. The
> only
> thing I can do is make it invisible/visible with an IIF statement. I know
> in
> Crystal Reports you could check a box that said "SUPPRESS IF BLANK" and
> this
> would move all the other fields up on the report accordingly. With SQL
> Reporting services it doesn't adjust the fields underneath it so I have a
> blank/empty space. Does anyone know of any other things I can try.
> Thanks

Wednesday, March 7, 2012

How to store Zero length strings, numbers, dates?

I am used to storing Null when a value does not exist. I have been told to
store "zero length strings" in some cases instead. Fine . . .
I do not know how to generate a "zero length string" or a "zero length
number" or anything else "zero length." But I suspect it is simple. Can you
provide a few simple examples?
Thanks
Michaelset columnName = '' (that's 2 single quotes)
for a zero length string.
If the column is a character data type, no problem.
If it's an Int though, the column will return a 0, not necessarily what you
want.
"Snake" <Snake@.discussions.microsoft.com> wrote in message
news:60BEB714-6B32-473A-8CD6-9036620F3892@.microsoft.com...
>I am used to storing Null when a value does not exist. I have been told to
> store "zero length strings" in some cases instead. Fine . . .
> I do not know how to generate a "zero length string" or a "zero length
> number" or anything else "zero length." But I suspect it is simple. Can
> you
> provide a few simple examples?
> Thanks
> Michael
>|||Why are you told to store zero length string? Null is a perfectly good value
especially for cases where the value is unknown.
Anyway, zero length is equivalent to "".
e.g.
create table tb(abc varchar(10) not null)
insert tb values('abc')
insert tb values('')
insert tb values('def')
-oj
"Snake" <Snake@.discussions.microsoft.com> wrote in message
news:60BEB714-6B32-473A-8CD6-9036620F3892@.microsoft.com...
>I am used to storing Null when a value does not exist. I have been told to
> store "zero length strings" in some cases instead. Fine . . .
> I do not know how to generate a "zero length string" or a "zero length
> number" or anything else "zero length." But I suspect it is simple. Can
> you
> provide a few simple examples?
> Thanks
> Michael
>|||I prefer storing Nulls, but that's me. An empty string is typically designat
ed
by two single quotes like so:
Create Table Foo
(
Bar VarChar(10)
)
Insert Foo (Bar) Values('')
There is no such thing as a "zero length number." If the value is a number,
then
it must have a numerical representation or be null. There is nothing in betw
een.
If the value is a string that has a number in it (e.g. '0' as opposed to 0),
then it is obviously the rules above apply.
Thomas
"Snake" <Snake@.discussions.microsoft.com> wrote in message
news:60BEB714-6B32-473A-8CD6-9036620F3892@.microsoft.com...
>I am used to storing Null when a value does not exist. I have been told to
> store "zero length strings" in some cases instead. Fine . . .
> I do not know how to generate a "zero length string" or a "zero length
> number" or anything else "zero length." But I suspect it is simple. Can y
ou
> provide a few simple examples?
> Thanks
> Michael
>|||Another thing:
A zero length string in a date column will also not work as you think.
"Raymond D'Anjou" <rdanjou@.savantsoftNOSPAM.net> wrote in message
news:%23T4$yKOTFHA.2680@.tk2msftngp13.phx.gbl...
> set columnName = '' (that's 2 single quotes)
> for a zero length string.
> If the column is a character data type, no problem.
> If it's an Int though, the column will return a 0, not necessarily what
> you want.
> "Snake" <Snake@.discussions.microsoft.com> wrote in message
> news:60BEB714-6B32-473A-8CD6-9036620F3892@.microsoft.com...
>|||Null is a perfectly good value *only* for cases where the value is unknown
:)
The OP said that he was told to store zero-length strings in "some cases
instead." This tells me that in some instances they recognize that the
value is not "unknown", but rather is is "known to be nothing".
Middle names are a perfect example. If you don't know someone's middle
name, you could use NULL to indicate it is unknown. If you know that the
person has *no* middle name, you could use '' to indicate that this person
has no middle name, and that you recognize this fact.
"oj" <nospam_ojngo@.home.com> wrote in message
news:%23$IbhMOTFHA.3544@.TK2MSFTNGP12.phx.gbl...
> Why are you told to store zero length string? Null is a perfectly good
> value especially for cases where the value is unknown.
> Anyway, zero length is equivalent to "".
> e.g.
> create table tb(abc varchar(10) not null)
> insert tb values('abc')
> insert tb values('')
> insert tb values('def')
> --
> -oj
>
> "Snake" <Snake@.discussions.microsoft.com> wrote in message
> news:60BEB714-6B32-473A-8CD6-9036620F3892@.microsoft.com...
>|||He also says that they want to store zero-length strings in numeric and date
columns.
That one I really don't get.
Even if you could store it, what would a zero-length string mean in these
cases?
"Michael C#" <howsa@.boutdat.com> wrote in message
news:%235Ak%23UOTFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Null is a perfectly good value *only* for cases where the value is unknown
> :)
> The OP said that he was told to store zero-length strings in "some cases
> instead." This tells me that in some instances they recognize that the
> value is not "unknown", but rather is is "known to be nothing".
> Middle names are a perfect example. If you don't know someone's middle
> name, you could use NULL to indicate it is unknown. If you know that the
> person has *no* middle name, you could use '' to indicate that this person
> has no middle name, and that you recognize this fact.
>
> "oj" <nospam_ojngo@.home.com> wrote in message
> news:%23$IbhMOTFHA.3544@.TK2MSFTNGP12.phx.gbl...
>|||Some people store dates in CHAR columns. Not something I would recommend,
but to each his/her own. The only other way around storing NULLs in numeric
and DATETIME columns would be to define a value that is out of range for
your purposes. For instance "9999-12-31" for an out of range date. Of
course then you introduce the Y10K problem which will have your great,
great, great, great, great (x 100's) grandchildren pulling out their hair
and cursing the day you were born...
"Raymond D'Anjou" <rdanjou@.savantsoftNOSPAM.net> wrote in message
news:e$MCzbOTFHA.2424@.TK2MSFTNGP09.phx.gbl...
> He also says that they want to store zero-length strings in numeric and
> date columns.
> That one I really don't get.
> Even if you could store it, what would a zero-length string mean in these
> cases?
> "Michael C#" <howsa@.boutdat.com> wrote in message
> news:%235Ak%23UOTFHA.3280@.TK2MSFTNGP09.phx.gbl...
>|||I would like to thank everyone who responded!
The individual who told me store "zero length strings" feels this "saves
space" and is "more efficient" than storing NULL. I know there are
length-indiocators and Null-indicators stored on the database page but I
don't exactly know their behaviors. My position has always been that storin
g
NULL is way less than 1% of the space normally used by data, so don't worry
about it. Am I overlooking something "material?"
Michael
"oj" wrote:

> Why are you told to store zero length string? Null is a perfectly good val
ue
> especially for cases where the value is unknown.
> Anyway, zero length is equivalent to "".
> e.g.
> create table tb(abc varchar(10) not null)
> insert tb values('abc')
> insert tb values('')
> insert tb values('def')
> --
> -oj
>
> "Snake" <Snake@.discussions.microsoft.com> wrote in message
> news:60BEB714-6B32-473A-8CD6-9036620F3892@.microsoft.com...
>
>|||zero-length neurons?
"Raymond D'Anjou" wrote:

> He also says that they want to store zero-length strings in numeric and da
te
> columns.
> That one I really don't get.
> Even if you could store it, what would a zero-length string mean in these
> cases?
> "Michael C#" <howsa@.boutdat.com> wrote in message
> news:%235Ak%23UOTFHA.3280@.TK2MSFTNGP09.phx.gbl...
>
>

Friday, February 24, 2012

how to store an "" value in my database instead of null

I have a problem I 'get stuck on it. i hope someone can help me.

I have a SQLServer table with an ID-field with a primary key and identity on it, and a couple of other fields with defaultvalue "" and NOT nullable

When i like to update an record in an formview of ASP 2.0 and fill in all fields everything is updated and everything goes fine

but

when I leave one field blank then I get the message 'can not enter null value in column X'

even when I place in the Updateparameter in my code

<asp:Parameter Name="Name" DefaultValue="" /> ASP tries to update an Null value

when i place an space as default value like

<asp:Parameter Name="Name" DefaultValue=" " />

everything goes fine exept there is an space in my database.

How can I update my record, and leave some textboxes emtpy AND where my fields are NOT nullable

I'm getting desparate of this.

make my fields nullable is not an option because this is a 'customerswish'

Please help

There is another property of the parameter, something like nullempty, or emptynull, nullifyemtpy. Because all form variables are encoded as strings, you can't really represent the null value, and in most cases where you are doing form entry from the web, leaving a field blank should enter a null value (As if the value is unknown/unspecified), so the default for this property of the parameter is ON.|||

Thanks a lot, that's the one.

Shame on me, why haven't I see this setting.

is this new in 2005 (I've previously working with Beta 2) and this occur in my 2005 projects

Thanks

Sunday, February 19, 2012

How to stop report parameter taking default value

I have a SSRS2000 report with three parameters:
1) Company - values from a query including NULL for ALL companies - no
default value
2) From date - has default value
3) To date - has default value
My problem is that the report runs automatically when launched. Even though
there is no default value specified for the Company parameter it takes the
NULL value.
Is there any way to change this to force the Company prompt to display a
<select a value> and allow selection of one of the options?
--
Magendo_man
Freelance SQL Reporting Services developer
Stirling, ScotlandHello magendo_man,
Instead of letting it take the value or NULL... change to: (CompanyID =@.Company OR @.CompanyID = "ALL"). Then in your query that supplies the
company names add a UNION SELECT "ALL". Don't specify a default for that
parameter.
Hope that helps!
Cheers,
Kathy
"magendo_man" wrote:
> I have a SSRS2000 report with three parameters:
> 1) Company - values from a query including NULL for ALL companies - no
> default value
> 2) From date - has default value
> 3) To date - has default value
> My problem is that the report runs automatically when launched. Even though
> there is no default value specified for the Company parameter it takes the
> NULL value.
> Is there any way to change this to force the Company prompt to display a
> <select a value> and allow selection of one of the options?
>
> --
> Magendo_man
> Freelance SQL Reporting Services developer
> Stirling, Scotland