Hi,
I would like to do a check in a SP if a table is empty.
How do i do that?
Thanksif exists(select * from <your table>)
select 'not empty'
else
select 'empty'|||Originally posted by Paul Young
if exists(select * from <your table>)
select 'not empty'
else
select 'empty'
Great..
Thaks
Showing posts with label empty. Show all posts
Showing posts with label empty. Show all posts
Thursday, March 22, 2012
Check if SqlDataSource is Empty in CodeBehind
This is probably an easy one.
What is best way to determine if a SqlDataSource is empty (i.e. the query produced no results) in the CodeBehind?
I'm using this:
if (SqlDataSource1.SelectCommand.Contains(String.Empty))
{
//Add code for scenario here.
}
It seems to work, but something just doesn't feel right about it for some reason.
Thanks
Not sure if this is better than your method, but you can always handle the Selected event for your SqlDataSource control to find out how many rows were returned from the query:
protectedvoid SqlDataSource1_Selected(object sender,SqlDataSourceStatusEventArgs e)
{
int ct = e.AffectedRows;
}
|||I'm trying to do the exact thing. Any other alternatives?
Labels:
codebehind,
codebehindi,
database,
determine,
empty,
microsoft,
mysql,
oracle,
produced,
query,
server,
sql,
sqldatasource
Check if image column is empty
Currently I use the follow Select statement to test if a non-nullable image
column is empty and not null:
Select Case When Substring(ImageColumn,1,1)='' Then 1 Else 0 End As IsEmpty
Can any body show me a better way to check if a column (non-nullable column)
of image data type is empty.DataLength(ColName) will be zero (0) if it's empty...
"krygim" wrote:
> Currently I use the follow Select statement to test if a non-nullable imag
e
> column is empty and not null:
> Select Case When Substring(ImageColumn,1,1)='' Then 1 Else 0 End As IsEmpt
y
> Can any body show me a better way to check if a column (non-nullable colum
n)
> of image data type is empty.
>
>|||Or, actually, just check if the column's value itself = '' (empty string)...
That should work. you don't need to attempt to extract the first character
and test that...
"krygim" wrote:
> Currently I use the follow Select statement to test if a non-nullable imag
e
> column is empty and not null:
> Select Case When Substring(ImageColumn,1,1)='' Then 1 Else 0 End As IsEmpt
y
> Can any body show me a better way to check if a column (non-nullable colum
n)
> of image data type is empty.
>
>|||Thanks
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:380D392D-B82A-493E-AA22-C137F4599577@.microsoft.com...
> DataLength(ColName) will be zero (0) if it's empty...
> "krygim" wrote:
>
image
IsEmpty
column)|||I got the error message: "The text, ntext, and image data types cannot be
compared or sorted."
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:3ADDA38D-0AC0-4377-9933-182222F35875@.microsoft.com...
> Or, actually, just check if the column's value itself = '' (empty
string)...
> That should work. you don't need to attempt to extract the first
character
> and test that...
>
> "krygim" wrote:
>
image
IsEmpty
column)|||Yes, you're right, DataLength() is the only other way...
"krygim" wrote:
> I got the error message: "The text, ntext, and image data types cannot be
> compared or sorted."
>
> "CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
> news:3ADDA38D-0AC0-4377-9933-182222F35875@.microsoft.com...
> string)...
> character
> image
> IsEmpty
> column)
>
>
column is empty and not null:
Select Case When Substring(ImageColumn,1,1)='' Then 1 Else 0 End As IsEmpty
Can any body show me a better way to check if a column (non-nullable column)
of image data type is empty.DataLength(ColName) will be zero (0) if it's empty...
"krygim" wrote:
> Currently I use the follow Select statement to test if a non-nullable imag
e
> column is empty and not null:
> Select Case When Substring(ImageColumn,1,1)='' Then 1 Else 0 End As IsEmpt
y
> Can any body show me a better way to check if a column (non-nullable colum
n)
> of image data type is empty.
>
>|||Or, actually, just check if the column's value itself = '' (empty string)...
That should work. you don't need to attempt to extract the first character
and test that...
"krygim" wrote:
> Currently I use the follow Select statement to test if a non-nullable imag
e
> column is empty and not null:
> Select Case When Substring(ImageColumn,1,1)='' Then 1 Else 0 End As IsEmpt
y
> Can any body show me a better way to check if a column (non-nullable colum
n)
> of image data type is empty.
>
>|||Thanks
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:380D392D-B82A-493E-AA22-C137F4599577@.microsoft.com...
> DataLength(ColName) will be zero (0) if it's empty...
> "krygim" wrote:
>
image
IsEmpty
column)|||I got the error message: "The text, ntext, and image data types cannot be
compared or sorted."
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:3ADDA38D-0AC0-4377-9933-182222F35875@.microsoft.com...
> Or, actually, just check if the column's value itself = '' (empty
string)...
> That should work. you don't need to attempt to extract the first
character
> and test that...
>
> "krygim" wrote:
>
image
IsEmpty
column)|||Yes, you're right, DataLength() is the only other way...
"krygim" wrote:
> I got the error message: "The text, ntext, and image data types cannot be
> compared or sorted."
>
> "CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
> news:3ADDA38D-0AC0-4377-9933-182222F35875@.microsoft.com...
> string)...
> character
> image
> IsEmpty
> column)
>
>
Labels:
case,
column,
database,
empty,
image,
imagecolumn,
microsoft,
mysql,
non-nullable,
nullselect,
oracle,
select,
server,
sql,
statement
Sunday, March 11, 2012
Check Constraint isse
I have a UnitOf Measure Filed. I wish to constrain it to "KG", "LBS", or
empty.
If I add ' or UnitOfMeasure = null' to the check constraint all values are
accepted. Without it a value MUST be specified. How do I limit the
possibilities to "KG", "LBS", empty?Remember, empty string and NULL are not the same thing...
CHECK UnitOfMeasure IN ('KG', 'LBS', '')
"bnhcomputing" <bnhcomputing@.discussions.microsoft.com> wrote in message
news:20151DE9-9B03-47AC-BCC4-E749A7D80497@.microsoft.com...
> I have a UnitOf Measure Filed. I wish to constrain it to "KG", "LBS", or
> empty.
> If I add ' or UnitOfMeasure = null' to the check constraint all values are
> accepted. Without it a value MUST be specified. How do I limit the
> possibilities to "KG", "LBS", empty?
empty.
If I add ' or UnitOfMeasure = null' to the check constraint all values are
accepted. Without it a value MUST be specified. How do I limit the
possibilities to "KG", "LBS", empty?Remember, empty string and NULL are not the same thing...
CHECK UnitOfMeasure IN ('KG', 'LBS', '')
"bnhcomputing" <bnhcomputing@.discussions.microsoft.com> wrote in message
news:20151DE9-9B03-47AC-BCC4-E749A7D80497@.microsoft.com...
> I have a UnitOf Measure Filed. I wish to constrain it to "KG", "LBS", or
> empty.
> If I add ' or UnitOfMeasure = null' to the check constraint all values are
> accepted. Without it a value MUST be specified. How do I limit the
> possibilities to "KG", "LBS", empty?
Subscribe to:
Posts (Atom)