Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Wednesday, March 28, 2012

Numbering each row in my resultset

In my query I want to succesively number each record I retrieve from a table.
Example: select <...>, state from tbl_states (<...> is what I am asking for)
Col1 Col2
1 Ohio
2 New York
3 California
4 Texas
I have seen some solutions using count(*), group by and joins to achieve
this. However I have images that I retrieve in columns 2 (instead of the
states) and group by is not compliant with image datatype.
I think Oracle has something called rownum that does what I want, but I
don't know how to do this with SQL Server.
Anybody knows?
Why not add the row number client-side? That can work out much more
efficient than any of the potential SQL solutions. Here's one SQL
alternative:
SELECT
(SELECT COUNT(*)
FROM YourTable
WHERE key_col <= T.key_col) AS col1,
col2
FROM YourTable AS T
David Portas
SQL Server MVP
|||Why make the query treat each row individually? The client has to do that
anyway, so it is a much more appropriate place to keep a running count.
http://www.aspfaq.com/
(Reverse address to reply.)
"Billy" <Billy@.discussions.microsoft.com> wrote in message
news:D2BEB8E4-C710-4027-A1EF-1D8166A6DB10@.microsoft.com...
> In my query I want to succesively number each record I retrieve from a
table.
> Example: select <...>, state from tbl_states (<...> is what I am asking
for)
> Col1 Col2
> --
> 1 Ohio
> 2 New York
> 3 California
> 4 Texas
> I have seen some solutions using count(*), group by and joins to achieve
> this. However I have images that I retrieve in columns 2 (instead of the
> states) and group by is not compliant with image datatype.
> I think Oracle has something called rownum that does what I want, but I
> don't know how to do this with SQL Server.
> Anybody knows?
>

Monday, March 26, 2012

Numbering each row in my resultset

In my query I want to succesively number each record I retrieve from a table.
Example: select <...>, state from tbl_states (<...> is what I am asking for)
Col1 Col2
--
1 Ohio
2 New York
3 California
4 Texas
I have seen some solutions using count(*), group by and joins to achieve
this. However I have images that I retrieve in columns 2 (instead of the
states) and group by is not compliant with image datatype.
I think Oracle has something called rownum that does what I want, but I
don't know how to do this with SQL Server.
Anybody knows?Why not add the row number client-side? That can work out much more
efficient than any of the potential SQL solutions. Here's one SQL
alternative:
SELECT
(SELECT COUNT(*)
FROM YourTable
WHERE key_col <= T.key_col) AS col1,
col2
FROM YourTable AS T
--
David Portas
SQL Server MVP
--|||Why make the query treat each row individually? The client has to do that
anyway, so it is a much more appropriate place to keep a running count.
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Billy" <Billy@.discussions.microsoft.com> wrote in message
news:D2BEB8E4-C710-4027-A1EF-1D8166A6DB10@.microsoft.com...
> In my query I want to succesively number each record I retrieve from a
table.
> Example: select <...>, state from tbl_states (<...> is what I am asking
for)
> Col1 Col2
> --
> 1 Ohio
> 2 New York
> 3 California
> 4 Texas
> I have seen some solutions using count(*), group by and joins to achieve
> this. However I have images that I retrieve in columns 2 (instead of the
> states) and group by is not compliant with image datatype.
> I think Oracle has something called rownum that does what I want, but I
> don't know how to do this with SQL Server.
> Anybody knows?
>

Numbering each row in my resultset

In my query I want to succesively number each record I retrieve from a table
.
Example: select <...>, state from tbl_states (<...> is what I am asking for
)
Col1 Col2
--
1 Ohio
2 New York
3 California
4 Texas
I have seen some solutions using count(*), group by and joins to achieve
this. However I have images that I retrieve in columns 2 (instead of the
states) and group by is not compliant with image datatype.
I think Oracle has something called rownum that does what I want, but I
don't know how to do this with SQL Server.
Anybody knows?Why not add the row number client-side? That can work out much more
efficient than any of the potential SQL solutions. Here's one SQL
alternative:
SELECT
(SELECT COUNT(*)
FROM YourTable
WHERE key_col <= T.key_col) AS col1,
col2
FROM YourTable AS T
David Portas
SQL Server MVP
--|||Why make the query treat each row individually? The client has to do that
anyway, so it is a much more appropriate place to keep a running count.
http://www.aspfaq.com/
(Reverse address to reply.)
"Billy" <Billy@.discussions.microsoft.com> wrote in message
news:D2BEB8E4-C710-4027-A1EF-1D8166A6DB10@.microsoft.com...
> In my query I want to succesively number each record I retrieve from a
table.
> Example: select <...>, state from tbl_states (<...> is what I am asking
for)
> Col1 Col2
> --
> 1 Ohio
> 2 New York
> 3 California
> 4 Texas
> I have seen some solutions using count(*), group by and joins to achieve
> this. However I have images that I retrieve in columns 2 (instead of the
> states) and group by is not compliant with image datatype.
> I think Oracle has something called rownum that does what I want, but I
> don't know how to do this with SQL Server.
> Anybody knows?
>

Numbering

I have a table with Employees, and the month and year they started. I need to number them in order of the month and year they started. Example: July 2001 is employee 1 and August 2001 is employee 2. However there may be multiple employees in a given month and year. It seems like this should be a simple task but I can not figure it out. I have a query that puts them in the right order but not sure how to update the ID with the correct number. I'm using Microsoft Access 2002.

Thanks

TheAceManPlease post that query. Also, what are the data types for month and year?sql

Number to words

hi
I want to know how convert number to words or words to number
for example. if i give input 100, i have to get the output "one hundred"
is there any built in function available. need solution immediately.
regards
nlakkaRun the attached script in PUBS database and see if that's what you want. I didn't have enough time to debug it, so if you find anything fishy, - just let me know.|||OK, it has bugs, so hang on...|||Alright, now it's good to go (I think). A little roughy, but good enough for check generation and similar stuff.|||I have tried running the script but it should even translate the cents and not
e.g. 50/100.

Good luck|||I have tried running the script but it should even translate the cents and not
e.g. 50/100.

Good luck
Hey, Why don't you try this link (http://sqlkit.com/blogs/rudra/archive/2006/04/10/104.aspx) ? Just make two part according to the position of the '.' decimal ,and add regional customization according to your choice.
I will add that functionality very soon ...
And use this logic to make it ...

set @.s='2344.34'
set @.part1=substring(@.s,1,(len(@.s)-3))
set @.part2=substring(@.s,(len(@.s)-1),2)

and pass it to the function. Hope u will do that easily ;)

Friday, March 23, 2012

Number of remain periods (Quarters, Months)

I will need to figure out how many remaining periods (remaining quarters, months) within a fiscal year. For example, today is still Jan, 07. So there will be 3 quarters remaining if my current member on time dimension is at quarter level. There will be 11 months remaining if my current member on time dimension is at month.

I need that numeric value in order to do some calculation.

How can I get that number?

Here's a sample Adventure Works query (only works below fiscal year level):

>>

with

Member [Measures].[YearEndCount] as

count({[Date].[Fiscal].NextMember:

ClosingPeriod([Date].[Fiscal].CurrentMember.Level,

Ancestor([Date].[Fiscal].CurrentMember,

[Date].[Fiscal].[Fiscal Year]))})

select {[Measures].[YearEndCount]} on 0,

Head(Descendants([Date].[Fiscal].[Fiscal Year].&[2003],

[Date].[Fiscal].[Fiscal Year], AFTER), 5) on 1

from [Adventure Works]

--

YearEndCount
H1 FY 2003 1
Q1 FY 2003 3
July 2002 11
July 1, 2002 364
July 2, 2002 363

>>

Wednesday, March 21, 2012

Number of duplicate record

I need help writing a query that can tell me the number of records with the
same content.
For example, this is my database (Data1 only has 1 column)
Table Data1
Column numbers
234
322
2323
234
453
234
412
2323
the query should like something like this
Select ..... From Data1 Where ... numbers =..
if i use
Select ..... From Data1 Where ... numbers = 234
it would return 3, because there are 3 234s in the column
Thanks in Advance,
AaronHi Aaron,
You could try
Select count(*) from Data1 Where Numbers = 234
HTH
Barry|||Select count(*) From Data1 Where numbers = 234
"Aaron" <kuya789@.yahoo.com> wrote in message
news:%23$tXt9cHFHA.1392@.TK2MSFTNGP10.phx.gbl...
> I need help writing a query that can tell me the number of records with
the
> same content.
> For example, this is my database (Data1 only has 1 column)
> Table Data1
> Column numbers
> 234
> 322
> 2323
> 234
> 453
> 234
> 412
> 2323
> --
> the query should like something like this
> Select ..... From Data1 Where ... numbers =..
> if i use
> Select ..... From Data1 Where ... numbers = 234
> it would return 3, because there are 3 234s in the column
>
> Thanks in Advance,
> Aaron
>|||Aaron,
If you want count the duplicate Records for the whole table rather than
individually then use:
select count(*), Numbers
>From Data1
Group By Numbers
Having Count(Numbers) > 1
HTH
Barry|||thanks.
"Barry" <barry.oconnor@.singers.co.im> wrote in message
news:1109683340.054164.176760@.g14g2000cwa.googlegroups.com...
> Aaron,
> If you want count the duplicate Records for the whole table rather than
> individually then use:
> select count(*), Numbers
> Group By Numbers
> Having Count(Numbers) > 1
> HTH
> Barry
>

Number of Days Of Week

Hi,
I need to find the number of Mondays within a given date range.
Example: How many Mondays between 01/01/2006 and 06/30/2006.
Any suggestions on how to do this?
JimHere is a function that will do this for you.
CREATE FUNCTION dbo.fnDaysBetween
( @.StartDate datetime,
@.EndDate datetime,
@.ConcernDay char(2) -- MO, TU, WE, etc.
)
RETURNS int
AS
BEGIN
DECLARE @.Calendar table
( CalendarDate smalldatetime )
WHILE ( @.StartDate <= @.EndDate )
BEGIN
INSERT INTO @.Calendar
SELECT @.StartDate
SET @.StartDate = dateadd( day, 1, @.StartDate )
END
RETURN
( isnull((
SELECT DayCount
FROM ( SELECT
DayCount = count(1),
DayName = datename( dw, CalendarDate )
FROM @.Calendar
GROUP BY datename( dw, CalendarDate )
) dt
WHERE upper( left( DayName, 2 )) = @.ConcernDay
), 0 )
)
END
GO
SELECT dbo.fnDaysBetween( '10-01-2006', '11-30-2006', 'mo' )
SELECT dbo.fnDaysBetween( '10-01-2006', '11-30-2006', 'fr' )
SELECT dbo.fnDaysBetween( '10-06-2006', '10-10-2006', 'fr' )
SELECT dbo.fnDaysBetween( '10-06-2006', '10-10-2006', 'we' )
DROP FUNCTION dbo.fnDaysBetween
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
<Jim.Mueksch@.wellsfargo.com> wrote in message news:1161982262.413737.288480@.k70g2000cwa.goog
legroups.com...
> Hi,
>
>
> I need to find the number of Mondays within a given date range.
>
> Example: How many Mondays between 01/01/2006 and 06/30/2006.
>
> Any suggestions on how to do this?
>
>
> Jim
>

Number of Days Of Week

Hi,
I need to find the number of Mondays within a given date range.
Example: How many Mondays between 01/01/2006 and 06/30/2006.
Any suggestions on how to do this?
Jimdeclare @.date1 datetime set @.date1 = '20061001'
declare @.date2 datetime set @.date2 = '20061029'
declare @.anyMonday datetime set @.anyMonday = '19000102'
select
datediff(day,@.anyMonday,@.date2)/7 -
datediff(day,@.anyMonday,@.date1)/7 as MondayBetween
<Jim.Mueksch@.wellsfargo.com> wrote in message
news:1161982195.940615.282480@.k70g2000cwa.googlegroups.com...
> Hi,
>
> I need to find the number of Mondays within a given date range.
> Example: How many Mondays between 01/01/2006 and 06/30/2006.
> Any suggestions on how to do this?
>
> Jim
>sql

Number of Days Of Week

Hi,
I need to find the number of Mondays within a given date range.
Example: How many Mondays between 01/01/2006 and 06/30/2006.
Any suggestions on how to do this?
JimThis is a multi-part message in MIME format.
--=_NextPart_000_0573_01C6F9CF.B01CC5E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Here is a function that will do this for you.
CREATE FUNCTION dbo.fnDaysBetween
( @.StartDate datetime,
@.EndDate datetime,
@.ConcernDay char(2) -- MO, TU, WE, etc.
)
RETURNS int
AS
BEGIN
DECLARE @.Calendar table
( CalendarDate smalldatetime )
WHILE ( @.StartDate <=3D @.EndDate )
BEGIN
INSERT INTO @.Calendar
SELECT @.StartDate
SET @.StartDate =3D dateadd( day, 1, @.StartDate )
END
RETURN
( isnull(( SELECT DayCount
FROM ( SELECT DayCount =3D count(1), DayName =3D datename( dw, CalendarDate )
FROM @.Calendar
GROUP BY datename( dw, CalendarDate )
) dt
WHERE upper( left( DayName, 2 )) =3D @.ConcernDay
), 0 )
)
END
GO
SELECT dbo.fnDaysBetween( '10-01-2006', '11-30-2006', 'mo' )
SELECT dbo.fnDaysBetween( '10-01-2006', '11-30-2006', 'fr' )
SELECT dbo.fnDaysBetween( '10-06-2006', '10-10-2006', 'fr' )
SELECT dbo.fnDaysBetween( '10-06-2006', '10-10-2006', 'we' )
DROP FUNCTION dbo.fnDaysBetween
-- Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience. Most experience comes from bad judgment. - Anonymous
You can't help someone get up a hill without getting a little closer to =the top yourself.
- H. Norman Schwarzkopf
<Jim.Mueksch@.wellsfargo.com> wrote in message =news:1161982262.413737.288480@.k70g2000cwa.googlegroups.com...
> Hi,
> > > I need to find the number of Mondays within a given date range.
> > Example: How many Mondays between 01/01/2006 and 06/30/2006.
> > Any suggestions on how to do this?
> > > Jim
>
--=_NextPart_000_0573_01C6F9CF.B01CC5E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Here is a function that will do this =for you.
CREATE FUNCTION dbo.fnDaysBetween ( @.StartDate datetime, @.EndDate datetime, @.ConcernDay =char(2) -- MO, TU, WE, etc. ) RETURNS intAS BEGIN
=DECLARE @.Calendar table ( CalendarDate smalldatetime )
=WHILE ( @.StartDate <=3D @.EndDate =) BEGIN &nbs=p; INSERT INTO @.Calendar = SELECT @.StartDate  =; SET @.StartDate =3D dateadd( day, 1, @.StartDate ) END
RETURN ( =isnull(( &nb=sp; SELECT DayCount &=nbsp; FROM ( SELECT &nb=sp; &nbs=p; DayCount =3D count(1), &nb=sp; &nbs=p; DayName =3D datename( dw, CalendarDate ) &n=bsp; FROM @.Calendar = GROUP BY datename( dw, CalendarDate ) &n=bsp; ) dt &=nbsp; WHERE upper( left( DayName, 2 )) =3D @.ConcernDay &nbs=p; ), 0 ) =) ENDGO
SELECT dbo.fnDaysBetween( ='10-01-2006', '11-30-2006', 'mo' )SELECT dbo.fnDaysBetween( '10-01-2006', ='11-30-2006', 'fr' )SELECT dbo.fnDaysBetween( '10-06-2006', '10-10-2006', 'fr' =)SELECT dbo.fnDaysBetween( '10-06-2006', '10-10-2006', 'we' )
DROP FUNCTION dbo.fnDaysBetween
-- Arnie Rowland, =Ph.D.Westwood Consulting, Inc
Most good judgment comes from =experience. Most experience comes from bad judgment. - Anonymous
You can't help someone get up a hill =without getting a little closer to the top yourself.- H. Norman Schwarzkopf
wrote in message news:1161982262.413737.288480@.k70g2000cwa.googlegroups.com...> =Hi,> > > I need to =find the number of Mondays within a given date range.> > Example: How =many Mondays between 01/01/2006 and 06/30/2006.> > Any suggestions on =how to do this?> > > Jim>

--=_NextPart_000_0573_01C6F9CF.B01CC5E0--

Tuesday, March 20, 2012

Number of charts vary with respect to a parameter

Hi

I have a situation similar to this example - The X Axis represents the Date and the Y Axis represents the number of vehicles sold and the data i need to represent is the type of each vehicle(Line Graph). Hence there should be one graph for each Vehicle type. Is it possible to generate as many Chart Objects in the rdl file dynamically.

I tried representing all the lines in a single chart but the since the sales value is varied as an example for a particular vehicle type it shall vary from 10000 to 1000000 and for another it varies from 10 to 100. So one vehicle type gets represented clearly and the other looks like a straight line.

Please help with the solution.

Thanks

Saishyam

> Hence there should be one graph for each Vehicle type.

Ok, let's assume you have a VehicleType field. Steps:
1. Add a list to the report
2. Add a list grouping based on the expression: =Fields!VehicleType.Value
This will create one list instance per vehicle type.
3. Add a chart into the list (make sure the chart is really contained within the list instead of overlaying)
4. Design your chart

You should then get one chart per vehicle type at runtime.

-- Robert

|||

Hi Robert

Thanks for the reply, I feel it will definitely help me out. Also will the layout be automatically taken care or should i code for that also.

|||

Not sure what you mean exactly with "layout", but if you leave the y-axis maximum value blank, the individual charts will automatically scale the y-axis based on the actual data values.

-- Robert

Monday, March 19, 2012

number in words

Hy,

I use Reporting Services with Visual Studio and in my report I have to write the numbers of my data base in words. For example : "55" has to be written "fifty five".

I have to do that in two other langages: french and dutch.

But I don't know at all how to do that. I never used reporting service before. Can you help me?

Regards

The requirement you present is not a simple one and certainly is not something that supported out of the box.

Your best option is to create a table with the range of numbers you wish translated and a language code column and get some resource to generate the translations manually.

Unless you want to get into custom coding to parse the number and translate it into words in the desired language on the fly, which although an interesting prospect I would certainly not recommend.

|||

Hello Oolon,

I had the same requirement, but I had in english. I did not create a table insted I created two functions and called one from another. First function has all the table values and the second has all the logic.

http://www.planet-source-code.com/vb/scripts/ShowCodeAsText.asp?txtCodeId=439&lngWId=5

Hope this helps.

|||

This code is perfect

Thank you

number formatting w/in charts and colors

1) How do you format numbers within charts. My numbers are currently without
commas (ex. 20000) and decimals with no formattting ( example: 679.8906890).
I would like them to be prettier with commas ( 20,000) and just 2 decimal
places ( 679.89) , respectively.
2) How do I assign colors to certain data values on my charts?
Please help...thank you.
Sincerely,
AllisonOn your first question: Pull up Chart properties dialog, go to Y-axis tab,
and type in c2 for Format Code.
On your second question: Pull up Chart properties dialog, go to Data tab ->
Edit button -> Point Labels tab -> Check Show Point Labels checkbox -> Click
on the Label Style button. You can then choose color, font, etc. for your
data labels. You can use an expression for Color as follows: =iif(
Fields!UnitPrice.Value <= 400.0, "Orange", "Green")
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ha Vo" <ha.vo@.prometheuslabs.com> wrote in message
news:OMhiwxLdEHA.2408@.tk2msftngp13.phx.gbl...
> 1) How do you format numbers within charts. My numbers are currently
without
> commas (ex. 20000) and decimals with no formattting ( example:
679.8906890).
> I would like them to be prettier with commas ( 20,000) and just 2 decimal
> places ( 679.89) , respectively.
> 2) How do I assign colors to certain data values on my charts?
> Please help...thank you.
> Sincerely,
> Allison
>

Friday, March 9, 2012

Nulls being allowed when they shouldnt be?

I have a simple table, for some reason, certain columns seem to accept
Nulls even though they shouldn't, for example the I can set the 'Name'
field to Null using my web application or directly in Enterprise
Manager. field How do I prevent this? However the 'RecCreated' doess
not permit nulls.

CREATE TABLE [dbo].[Group] (
[GroupID] [int] IDENTITY (1000, 1) NOT NULL ,
[Name] [nvarchar] (50) NOT NULL ,
[Description] [nvarchar] (750) NULL ,
[RecCreated] [datetime] NOT NULL ,
[RecUpdated] [datetime] NOT NULL ,
[RecCreatedBy] [int] NOT NULL ,
[RecUpdatedBy] [int] NOT NULL ,
[RecActive] [int] NOT NULL
) ON [PRIMARY]
GO
thanks for any help you can give on thisIf your adding data to varchar field using EM are actually entering an empty
string? and most likely this is what your web application is doing as well.

1) You really shouldn't be using EM to enter data into your tables, or
rather you shouldn't be relying on it as a primary means to enter data.
It's great for testing and the like but it should be limitted to that.
2) It sounds like your web application needs some additional middle tier
logic to make sure that empty strings aren't passed into the database.

Hopefully these ideas help,
Muhd.

"grist2mill" <grist2mill@.excite.com> wrote in message
news:46e240e.0410080831.b3bd7d8@.posting.google.com ...
>I have a simple table, for some reason, certain columns seem to accept
> Nulls even though they shouldn't, for example the I can set the 'Name'
> field to Null using my web application or directly in Enterprise
> Manager. field How do I prevent this? However the 'RecCreated' doess
> not permit nulls.
>
> CREATE TABLE [dbo].[Group] (
> [GroupID] [int] IDENTITY (1000, 1) NOT NULL ,
> [Name] [nvarchar] (50) NOT NULL ,
> [Description] [nvarchar] (750) NULL ,
> [RecCreated] [datetime] NOT NULL ,
> [RecUpdated] [datetime] NOT NULL ,
> [RecCreatedBy] [int] NOT NULL ,
> [RecUpdatedBy] [int] NOT NULL ,
> [RecActive] [int] NOT NULL
> ) ON [PRIMARY]
> GO
> thanks for any help you can give on this|||Can you post some code that will reproduce the problem. I assume you are
aware that NULL is different to the empty string? How did you check that
NULLs were present in the table? Can you actually run the following queries
in Query Analzer and see what they return:

SELECT [name]
FROM dbo.[Group]
WHERE [name] IS NULL

SELECT COLUMNPROPERTY(OBJECT_ID('dbo.[Group]'),'name','AllowsNull')

You can't always believe what you see in Enterprise Manager because the
display isn't always refreshed when you would expect it to be. Also, I
wouldn't trust EM as a method for entering data into tables.

P.S. "GROUP" is a reserved word. It's not a good idea to use reserved words
for table names. Anyway "Group" is too meaningless to make a good table
name. Group of what?

--
David Portas
SQL Server MVP
--|||"grist2mill" <grist2mill@.excite.com> wrote in message
news:46e240e.0410080831.b3bd7d8@.posting.google.com ...
>I have a simple table, for some reason, certain columns seem to accept
> Nulls even though they shouldn't, for example the I can set the 'Name'
> field to Null using my web application or directly in Enterprise
> Manager. field How do I prevent this? However the 'RecCreated' doess
> not permit nulls.
>
> CREATE TABLE [dbo].[Group] (
> [GroupID] [int] IDENTITY (1000, 1) NOT NULL ,
> [Name] [nvarchar] (50) NOT NULL ,
> [Description] [nvarchar] (750) NULL ,
> [RecCreated] [datetime] NOT NULL ,
> [RecUpdated] [datetime] NOT NULL ,
> [RecCreatedBy] [int] NOT NULL ,
> [RecUpdatedBy] [int] NOT NULL ,
> [RecActive] [int] NOT NULL
> ) ON [PRIMARY]
> GO
> thanks for any help you can give on this

In Enterprise Manager, if you type NULL in the table data screen, it will
put the literal string 'NULL' into the table, which is not the same as a
real NULL; you need Ctrl+0 to get a real NULL. I suspect your application is
doing the same thing, or perhaps displaying an empty string as NULL, which
it isn't.

EM isn't a good application for modifying data, because it's not always
completely clear what it's doing. You should use Query Analyzer instead,
because then you can control every detail of the SQL you execute, and you
can also save scripts for future use more easily.

Simon|||Thanks to all for your help and tips.

So if I understand things correctly, (having run David's suggested
queries),

if you set a column to be nvarchar to not accept nulls, the column
will still accept empty strings. So to make a field mandatory, I must
enforce this at the application level (which is not such good
practice, because if another application should access the table I
won't know if they correctly enforce that certain fields should be
mandatory).

Have I understod things correctly (or should a be using a different
data type from nvarchar)?|||Thanks to all for your help and tips.

So if I understand things correctly, (having run David's suggested
queries),

if you set a column to be nvarchar to not accept nulls, the column
will still accept empty strings. So to make a field mandatory, I must
enforce this at the application level (which is not such good
practice, because if another application should access the table I
won't know if they correctly enforce that certain fields should be
mandatory).

Have I understod things correctly (or should a be using a different
data type from nvarchar)?|||On 11 Oct 2004 03:05:00 -0700, grist2mill wrote:

>if you set a column to be nvarchar to not accept nulls, the column
>will still accept empty strings. So to make a field mandatory, I must
>enforce this at the application level

Hi grist2mill,

You can use a CHECK constraint:

CREATE TABLE xxxx (...,
NonEmptyCol nvarchar(78) NOT NULL
CHECK (NonEmptyCol <> ''),
...)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Thanks Hugo,
thats the problem solved
regards
GM

Hugo Kornelis <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message news:<ouokm0loui5brq4hi1f7qnuqbdd4fm3kl0@.4ax.com>...
> On 11 Oct 2004 03:05:00 -0700, grist2mill wrote:
> >if you set a column to be nvarchar to not accept nulls, the column
> >will still accept empty strings. So to make a field mandatory, I must
> >enforce this at the application level
> Hi grist2mill,
> You can use a CHECK constraint:
> CREATE TABLE xxxx (...,
> NonEmptyCol nvarchar(78) NOT NULL
> CHECK (NonEmptyCol <> ''),
> ...)
> Best, Hugo

NULL+ x = NULL problem

Hi there,
Is there any setting in SQL that can disable this silly logic.
For example, in a number cleaning query I want to combine the Code and the Number

The problem is that I either the code or the number is null, I lose the number:


update tbl
set Teleh = CodeH + TeleH


I know that I can split this and check if one is null, both null, both non-null but i am sure there must be an easier way such as Accesses & operator

The way that I am using now does this, but i'm not sure if this is the best approach

update tbl
set Teleh = isnull(Codeh,'') + isnull(Teleh,'')


The problem with this is that the result is not stored as null, but as '' length 0The problem with this is that the result is not stored as null, but as '' length 0but that's exactly what you wanted!!

or are you saying that if they are both null then you want the result null?

in that case (pun intended),update tbl
set Teleh = case when CodeH is null
and TeleH is null
then null
else coalesce(CodeH,'')
+coalesce(TeleH,'')
end|||Sorry
Often, the entire number is stored in CodeH and Teleh is empty
So if a update it to Codeh + Teleh, I loose the correct number in Codeh

Monday, February 20, 2012

Null Paramemter in Store Procedure

Hi,
I am sending a an argument to a store procedure, I will
add a value to the "where" condition depending of that
parameter.
For example, the parameter is name, if i send "name1" I
will add "AND name = 'name'" to the store produre
(dynamic sql).
Is there a way to do it without concatenating it to a
nvarchar?
like "where name = *" or sometign like this?
Thanks a lot for your help!!
JCWithout dynamic SQL:
WHERE @.name IS NULL OR name = @.name
--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.
"Juan Carlos" <jcarlos_mn@.hotmail.com> wrote in message
news:03eb01c34431$51a993a0$a301280a@.phx.gbl...
> Hi,
> I am sending a an argument to a store procedure, I will
> add a value to the "where" condition depending of that
> parameter.
> For example, the parameter is name, if i send "name1" I
> will add "AND name = 'name'" to the store produre
> (dynamic sql).
> Is there a way to do it without concatenating it to a
> nvarchar?
> like "where name = *" or sometign like this?
> Thanks a lot for your help!!
> JC|||For a detailed list of options refer to:
http://www.algonet.se/~sommar/dyn-search.html
--
- Anith
( Please reply to newsgroups only )|||Hi JC,
You may try something like this:
ISNULL( 'AND name = ''' + @.name + ''', '')
then, if @.name is null, the condition won't appear in WHERE clause... hope
this help
--
---
Charlie Yukio Nakagawa
---
"Juan Carlos" <jcarlos_mn@.hotmail.com> escreveu na mensagem
news:03eb01c34431$51a993a0$a301280a@.phx.gbl...
> Hi,
> I am sending a an argument to a store procedure, I will
> add a value to the "where" condition depending of that
> parameter.
> For example, the parameter is name, if i send "name1" I
> will add "AND name = 'name'" to the store produre
> (dynamic sql).
> Is there a way to do it without concatenating it to a
> nvarchar?
> like "where name = *" or sometign like this?
> Thanks a lot for your help!!
> JC