Showing posts with label bit. Show all posts
Showing posts with label bit. Show all posts

Sunday, March 25, 2012

Calculated fields with Days/Dates

Preface: This is a bit of a long read, but if I cut too many corners it
would all sound like nonsense, so apologies in advance.
I'm working on application where customers may have a nominated carrier to
deliver goods to them on one of several given days. The carrier will collect
goods from us on say 2 days per w though this may change over time.
Currently we only have one carrier, though there may be more in time, and
they collect on Tuesdays & Thursdays.
Say we have a Customer with 2 depots; Depot A wants deliveries on a Tuesdays
& Thursday, and Depot B wants deliveries Mondays & Fridays.
When despatching a product, the user will first select a collection day (Tue
or Thu), which will then present them with a list of possible delivery
dates; so in this example, if Thursday was selected, if it was Depot A only
the following Tuesday would be offered, if it was Depot B both Friday &
Monday need to be offered. It is this code that is proving the problem for
me at the moment.
Architecture (Snipped DDL at end):
We have a Customers table that records the nominated Carrier for that
customer.
We have a Locations (i.e. Depots) table with a int field to store the
preferred DeliveryDays for that depot - so for Depot A, DeliveryDays=10
(where Tues = 2, Thurs=8, total = 10) which will be queried using bitwise
operators.
We have a CarrierCollections table which holds a record for each carrier,
for each day they collect on, which indicates what the possible delivery
dates for that collection date are:
e.g..
CarrierID - DeliveryDay - CollectionDays
6 - 2 - 12
6 - 8 - 23
12 = Weds/Thurs
23 = Mon/Tue/Fri
I can query for a given depot what delivery dates are appropriate:
Select CC.CollectionDay,(CC.DeliveryDays & L.DeliveryDays) as DeliveryDays
from Locations L
inner join Customers C on C.CustomerID = L.CustomerID
inner join CarrierCollections CC on CC.CarrierID = C.ManagedCarrierID
Where L.LocationID = @.LocationID
and (CC.DeliveryDays & L.DeliveryDays) > 0
and CC.CollectionDay = @.CollectionDay
which, for Depot A/Thursday collection returns:
CollectionDay DeliveryDays
-- --
8.00 2.00
For Depot B/Thursday Collection:
CollectionDay DeliveryDays
-- --
8.00 17.00
What I want to do now is to modify the query to return a row for each
delivery day including what the date of that delivery date would be, so for
Depot B example above, I want to return (if run today, 19th Aug):
CollectionDay DeliveryDay NextDate
-- -- --
8.00 Mon 22/08/05
8.00 Fri 26/08/05
And this is where I am stuck, I'm still working on it, but so far I haven't
found a (good) solution. I could handle this in my ASP application, but I'm
assuming that an SQL-only solution would be better(?).
I'm not sure if what I have done so far is a stroke of genius or a sign of
madness. I deliberated about storing the DeliveryDays for both the Depot and
the Carrier Collection tables in separate tables, but I was drawn to the
bitwise comparison route. I'm not sure if this is foolhardy or not!
So can this be done given my current architecture? If not, could it be done
if I took a different approach in SQL? Or should I stick with what I have,
and do the final steps in ASP?
Thanks in advance - you deserve a medal for reading this far...
Chris
DDL:
CREATE TABLE [dbo].[CarrierCollections] (
[CarrierID] [int] NOT NULL ,
[CollectionDay] [int] NOT NULL ,
[DeliveryDays] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Customers] (
[CustomerID] [int] IDENTITY (1, 1) NOT NULL ,
[CustomerName] [varchar] (30) COLLATE Latin1_General_CI_AS NOT NULL ,
[CustomerType] [tinyint] NULL ,
[ManagedCarrierID] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Locations] (
[LocationID] [int] IDENTITY (1, 1) NOT NULL ,
[LocationName] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL ,
[CustomerID] [int] NOT NULL ,
[DeliveryDays] [int] NOT NULL
) ON [PRIMARY]
GO
cjmnews04@.REMOVEMEyahoo.co.uk
[remove the obvious bits]It sounds like your database has problem with Normalization. This statemen
t
tells me that it is not in 1st NormalForm: DeliveryDays=10 (where Tues = 2,
Thurs=8, total = 10). It is not atomic field. I would suggest to redesign
your database first, then you will be easy to find out the solution.
Perayu
"CJM" wrote:

> Preface: This is a bit of a long read, but if I cut too many corners it
> would all sound like nonsense, so apologies in advance.
>
> I'm working on application where customers may have a nominated carrier to
> deliver goods to them on one of several given days. The carrier will colle
ct
> goods from us on say 2 days per w though this may change over time.
> Currently we only have one carrier, though there may be more in time, and
> they collect on Tuesdays & Thursdays.
> Say we have a Customer with 2 depots; Depot A wants deliveries on a Tuesda
ys
> & Thursday, and Depot B wants deliveries Mondays & Fridays.
> When despatching a product, the user will first select a collection day (T
ue
> or Thu), which will then present them with a list of possible delivery
> dates; so in this example, if Thursday was selected, if it was Depot A onl
y
> the following Tuesday would be offered, if it was Depot B both Friday &
> Monday need to be offered. It is this code that is proving the problem for
> me at the moment.
>
> Architecture (Snipped DDL at end):
> We have a Customers table that records the nominated Carrier for that
> customer.
> We have a Locations (i.e. Depots) table with a int field to store the
> preferred DeliveryDays for that depot - so for Depot A, DeliveryDays=10
> (where Tues = 2, Thurs=8, total = 10) which will be queried using bitwise
> operators.
> We have a CarrierCollections table which holds a record for each carrier,
> for each day they collect on, which indicates what the possible delivery
> dates for that collection date are:
> e.g..
> CarrierID - DeliveryDay - CollectionDays
> 6 - 2 - 12
> 6 - 8 - 23
> 12 = Weds/Thurs
> 23 = Mon/Tue/Fri
> I can query for a given depot what delivery dates are appropriate:
> Select CC.CollectionDay,(CC.DeliveryDays & L.DeliveryDays) as DeliveryDay
s
> from Locations L
> inner join Customers C on C.CustomerID = L.CustomerID
> inner join CarrierCollections CC on CC.CarrierID = C.ManagedCarrierID
> Where L.LocationID = @.LocationID
> and (CC.DeliveryDays & L.DeliveryDays) > 0
> and CC.CollectionDay = @.CollectionDay
> which, for Depot A/Thursday collection returns:
> CollectionDay DeliveryDays
> -- --
> 8.00 2.00
> For Depot B/Thursday Collection:
> CollectionDay DeliveryDays
> -- --
> 8.00 17.00
> What I want to do now is to modify the query to return a row for each
> delivery day including what the date of that delivery date would be, so fo
r
> Depot B example above, I want to return (if run today, 19th Aug):
> CollectionDay DeliveryDay NextDate
> -- -- --
> 8.00 Mon 22/08/05
> 8.00 Fri 26/08/05
> And this is where I am stuck, I'm still working on it, but so far I haven'
t
> found a (good) solution. I could handle this in my ASP application, but I'
m
> assuming that an SQL-only solution would be better(?).
> I'm not sure if what I have done so far is a stroke of genius or a sign of
> madness. I deliberated about storing the DeliveryDays for both the Depot a
nd
> the Carrier Collection tables in separate tables, but I was drawn to the
> bitwise comparison route. I'm not sure if this is foolhardy or not!
> So can this be done given my current architecture? If not, could it be don
e
> if I took a different approach in SQL? Or should I stick with what I have,
> and do the final steps in ASP?
> Thanks in advance - you deserve a medal for reading this far...
> Chris
> DDL:
> CREATE TABLE [dbo].[CarrierCollections] (
> [CarrierID] [int] NOT NULL ,
> [CollectionDay] [int] NOT NULL ,
> [DeliveryDays] [int] NOT NULL
> ) ON [PRIMARY]
> GO
> CREATE TABLE [dbo].[Customers] (
> [CustomerID] [int] IDENTITY (1, 1) NOT NULL ,
> [CustomerName] [varchar] (30) COLLATE Latin1_General_CI_AS NOT NULL ,
> [CustomerType] [tinyint] NULL ,
> [ManagedCarrierID] [int] NOT NULL
> ) ON [PRIMARY]
> GO
> CREATE TABLE [dbo].[Locations] (
> [LocationID] [int] IDENTITY (1, 1) NOT NULL ,
> [LocationName] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL ,
> [CustomerID] [int] NOT NULL ,
> [DeliveryDays] [int] NOT NULL
> ) ON [PRIMARY]
> GO
>
> --
> cjmnews04@.REMOVEMEyahoo.co.uk
> [remove the obvious bits]
>
>|||"Perayu" <Perayu@.discussions.microsoft.com> wrote in message
news:3398A112-FC1D-4E5C-931E-4BE3237E3FAF@.microsoft.com...
> It sounds like your database has problem with Normalization. This
> statement
> tells me that it is not in 1st NormalForm: DeliveryDays=10 (where Tues =
> 2,
> Thurs=8, total = 10). It is not atomic field. I would suggest to redesign
> your database first, then you will be easy to find out the solution.
>
You may well be right, but suggesting that there is a problem isnt the same
as identifying the problem, nor solving it. Also, in some situations, you
don't want to fully normalize the data for performance reasons; is this one
of those cases?
More importantly, what would you suggest the data structure should be?
By normalizing the data such that there are two extra tables to store the
DeliveryDays for the Depot's and the Carriers, you will change the SQl used
in my query, but you will still be left with the same problem in how to
determine the appropriate delivery & dates and sorted in the right order.|||I added a table:
CREATE TABLE [dbo].[LocationDeliveryDay] (
[LocationID] [tinyint] NOT NULL ,
[DeliveryDays] [tinyint] NOT NULL
) ON [PRIMARY]
GO
removed DeliveryDays from Locations table.
The DeliveryDays will be entered as Sunday - Saturday values as 1 - 7
Then your query will be modified as :
Select CC.CollectionDay,
LD.DeliveryDays,
DeliveryDay =
case when LD.DeliveryDays < (select Datepart(dw, (Getdate()))) then
(select dateadd(dd, (select Datepart(dw, (Getdate())) + LD.DeliveryDays -
4 ), getdate()))
else
(select dateadd(dd, (LD.DeliveryDays - (select Datepart(dw,
(Getdate())))), getdate()))
end
from Locations L
inner join LocationDeliveryDay LD on LD.LocationID = L.LocationID
inner join Customers C on C.CustomerID = L.CustomerID
inner join CarrierCollections CC on CC.CarrierID = C.ManagedCarrierID
Where L.LocationID = @.LocationId
and CC.CollectionDay = @.CollectionDay
When I tried to run this query with @.LocationId = 1, @.CollectionDay = 8 ,
the result will look like this:
CollectionDay DeliveryDays DeliveryDay
-- --
---
8 2 2005-08-23 11:47:28.933
8 4 2005-08-25 11:47:28.933
You can reformat the date result as whatever you want.
I just gave an example of how you could modify your tables so that you can
get what you want. If you are going to modify, you may want to modify table
CarrierCollections also.
Just an one cent idea.
Perayu
"CJM" wrote:

> "Perayu" <Perayu@.discussions.microsoft.com> wrote in message
> news:3398A112-FC1D-4E5C-931E-4BE3237E3FAF@.microsoft.com...
> You may well be right, but suggesting that there is a problem isnt the sam
e
> as identifying the problem, nor solving it. Also, in some situations, you
> don't want to fully normalize the data for performance reasons; is this on
e
> of those cases?
> More importantly, what would you suggest the data structure should be?
> By normalizing the data such that there are two extra tables to store the
> DeliveryDays for the Depot's and the Carriers, you will change the SQl use
d
> in my query, but you will still be left with the same problem in how to
> determine the appropriate delivery & dates and sorted in the right order.
>
>|||Thanks Perayu,
I'd already changed the structure a little; the CarrierCollections table now
has one record per Carrier, per collection day, per delivery day - which I'm
thinking is the kind of change you were hinting at. And I am currently
working on a function to calculate the date of the next delivery day(s).
However, I'll digest your suggestions and see if and how I can incorporate
them, before I go any further down the line. I'll post back with any useful
conclusions.
Thanks for your efforts
Chris|||why not build a calendar table somethgn like this?
CREATE TABLE Calendar
(cal_date DATETIME NOT NULL PRIMARY KEY,
mn_del DATETIME NOT NULL,
tu_del DATETIME NOT NULL,
.
fr_del DATETIME NOT NULL);
Now you can adjust for holidays and use temporal functions on the data.
I also hope you are nto acctually using IDENTITY for locations and
customers.|||Here's my version of this code:
Select L.LocationID, L.LocationName, DD.DeliveryDay,
Case when DD.DeliveryDay <= (Select DatePart(dw,GetDate())) then
(Select DateAdd(dd, 7 - (Select DatePart(dw,GetDate()) - DD.DeliveryDay),
GetDate()))
Else
(Select DateAdd(dd, DD.DeliveryDay - (Select DatePart(dw,GetDate())) ,
GetDate()))
End as NextDate
from Locations L
inner join DeliveryDays DD on DD.LocationID = L.LocationID
inner join Customers C on C.CustomerID = L.CustomerID
inner join CarrierCollections CC on CC.CarrierID = C.ManagedCarrierID
and CC.DeliveryDay = DD.DeliveryDay
where L.LocationID = @.LocationID
and CC.CollectionDay = @.CollectionDay
Order By CollectionDay
I notice it varies from yours within the case statement, but it seems to
work fine for me.
I'm not sure I quite understand your approach. It may be incorrect , but I
haven't tested it fully.
Anyway, thanks for your help...
Chris

Thursday, March 22, 2012

calculated field crashes Vs 2005 sp1 ?

Hi!

when I'm trying something litle bit more complex thing than string manipulation in calculated field ex: =RunningValue(Fields!SALES.Value, Sum)


It just crashes visual studio when trying to run the report?! I think this could state as a bug in RS?

RunningValue requires 3 parameters (Expression, function and scope)

Edit Expression dialog may offer a choice with 2 parameters, that is a bug.

|||

Hi!

Thanks for a quick reply, but this did'nt solve this.

Maybe I'll explain little bit
I want to have cumulative sum value over the data. So I open datasource and add new field, and check this field as calculated field with expression : =RunningValue(Fields!SALES.Value, Sum, "DataSource1")

Then I click preview panel and Visual studio waits some seconds and crashes!!!

I really need this beacause Customer needs to have cumulative sales groups


Product Sales Cumulative %
A group
Product1 100 100 28%
Product2 70 170 48%
B group 170 48%
Product3 60 230 65%
Product4 50 280 80%
C group 280 80%
Product5 40 320 91%
Product6 30 350 100%


And the grouping is dynamic. Ex all cumulative sales less than 0% belongs to the group A sales below 80% belongs to B and others are in group C
At this moment I'm feeling pretty desperate on this case and it seems it is not possible to do this by report services!

|||Aggregate functions are not allowed in calculated fields|||

Seems that I found a solution.
Beacause this cannot be done wiht RS I had load data into data table, do inner calculations and then
pass this data to RS.

I don't understand design decisions of this? Why it's not possible to RS that Headers would accept data from inner fields as a criteria. This report creation process seems to be very waterfall aproach, no precalculations :(

calculated field crashes Vs 2005 sp1 ?

Hi!

when I'm trying something litle bit more complex thing than string manipulation in calculated field ex: =RunningValue(Fields!SALES.Value, Sum)


It just crashes visual studio when trying to run the report?! I think this could state as a bug in RS?

RunningValue requires 3 parameters (Expression, function and scope)

Edit Expression dialog may offer a choice with 2 parameters, that is a bug.

|||

Hi!

Thanks for a quick reply, but this did'nt solve this.

Maybe I'll explain little bit
I want to have cumulative sum value over the data. So I open datasource and add new field, and check this field as calculated field with expression : =RunningValue(Fields!SALES.Value, Sum, "DataSource1")

Then I click preview panel and Visual studio waits some seconds and crashes!!!

I really need this beacause Customer needs to have cumulative sales groups


Product Sales Cumulative %
A group
Product1 100 100 28%
Product2 70 170 48%
B group 170 48%
Product3 60 230 65%
Product4 50 280 80%
C group 280 80%
Product5 40 320 91%
Product6 30 350 100%


And the grouping is dynamic. Ex all cumulative sales less than 0% belongs to the group A sales below 80% belongs to B and others are in group C
At this moment I'm feeling pretty desperate on this case and it seems it is not possible to do this by report services!

|||Aggregate functions are not allowed in calculated fields|||

Seems that I found a solution.
Beacause this cannot be done wiht RS I had load data into data table, do inner calculations and then
pass this data to RS.

I don't understand design decisions of this? Why it's not possible to RS that Headers would accept data from inner fields as a criteria. This report creation process seems to be very waterfall aproach, no precalculations :(

sql

Calculate Yearly Sales Difference

Hello,
I've been using Crystal Reports a little bit for about a year now, but have never created a report like this.

The report I am working on displays:
CUSTOMER
2005 SALES $000000.00
2006 SALES $000000.00
TOTAL SALES $000000.00
$ DIFFERENCE $000000.00
% DIFFERENCE $000000.00

I am able to bring up the yearly sales and total sales, but I cannot figure out how to calculate the difference. Any help will be greatly appreciated.

Thank you.I think you must create a query in command query in database expert:
one command query for select sum(sales) from tablename where year=2005 group by year... also another command query for 2006 and compute the difference between the two field in report using formula.

i know it is not nice suggestion but if you have no other idea then try this.|||Thanks for the idea.
I'll take a look and see if I can get it to work.sql

Monday, March 19, 2012

calculate base 32 notation from int value?

hello everyone,
i have an artificial keying system that is based upon a psuedo-randomly
changing 31 bit pattern stored in the database as an int.
the current key is stored in a table like so:
create table artificialkeys (
keyname varchar(50) primary key not null,
keyvalue int)
go
insert into artificialkeys (keyname, keyvalue)
values ('accountnumber', 1)
go
and the key is used by an entity such as this:
create table accounts (
accountnumber int primary key not null,
accountname varchar(50) not null)
go
and the key is incremented / implemented with stored procedures, such
as this:
create procedure [owner].[insert_account] (
@.accountnumber int output,
@.accountname varchar(50))
as
update artificialkeys set keyvalue = @.accountnumber = (currentvalue /
2) + ((currentvalue % 2 + ((currentvalue / 8) % 2)) % 2) * power(2, 30)
where keyname = 'accountnumber'
insert into accounts (accountnumber, accountname)
values (@.artificialkey, @.accountname)
go
this is the current setup, and it's working just fine. we get a
pseudo-random integer as our primary key with a value between 1 and
2^31 (due to the nature of the algorithm which i won't get into).
now comes the problem, and my question. these account numbers are
presented as ten digit strings to the customers (with leading zeros as
necessary), such as '0054613854', just a string version of the decimal
int value. no problem.
however we are moving to new accounting software, and there is a limit
of 6 characters for the account number, but it can still be
alphanumeric. and that brings me to my current plan. the value range,
if represented in base32 notation, would be from 1 to 4000, well within
the range the new software needs.
but this presents some problems that i thought i'd ask here. for
example, in base32 notation, some values are no longer acceptible. for
instance, i don't want someone ending up with the account number 'XXXX'
... so i'd like to impose a restriction that no more than two
consecutive digits can be above 9 in value.
also i'm not sure how i can convert the int value into a base32
representation inside the stored procedure, to be stored as a string
primary key?
the more i think about this the more it seems like i should handle this
in the middleware?
thanks for any thoughts,
jasonjason wrote:
> hello everyone,
> i have an artificial keying system that is based upon a psuedo-randomly
> changing 31 bit pattern stored in the database as an int.
> the current key is stored in a table like so:
> create table artificialkeys (
> keyname varchar(50) primary key not null,
> keyvalue int)
> go
> insert into artificialkeys (keyname, keyvalue)
> values ('accountnumber', 1)
> go
> and the key is used by an entity such as this:
> create table accounts (
> accountnumber int primary key not null,
> accountname varchar(50) not null)
> go
> and the key is incremented / implemented with stored procedures, such
> as this:
> create procedure [owner].[insert_account] (
> @.accountnumber int output,
> @.accountname varchar(50))
> as
> update artificialkeys set keyvalue = @.accountnumber = (currentvalue /
> 2) + ((currentvalue % 2 + ((currentvalue / 8) % 2)) % 2) * power(2, 30)
> where keyname = 'accountnumber'
> insert into accounts (accountnumber, accountname)
> values (@.artificialkey, @.accountname)
> go
> this is the current setup, and it's working just fine. we get a
> pseudo-random integer as our primary key with a value between 1 and
> 2^31 (due to the nature of the algorithm which i won't get into).
> now comes the problem, and my question. these account numbers are
> presented as ten digit strings to the customers (with leading zeros as
> necessary), such as '0054613854', just a string version of the decimal
> int value. no problem.
> however we are moving to new accounting software, and there is a limit
> of 6 characters for the account number, but it can still be
> alphanumeric. and that brings me to my current plan. the value range,
> if represented in base32 notation, would be from 1 to 4000, well within
> the range the new software needs.
> but this presents some problems that i thought i'd ask here. for
> example, in base32 notation, some values are no longer acceptible. for
> instance, i don't want someone ending up with the account number 'XXXX'
> ... so i'd like to impose a restriction that no more than two
> consecutive digits can be above 9 in value.
> also i'm not sure how i can convert the int value into a base32
> representation inside the stored procedure, to be stored as a string
> primary key?
> the more i think about this the more it seems like i should handle this
> in the middleware?
> thanks for any thoughts,
> jason
To eliminate the offensive words why not just exclude vowels from the
account numbers. That would only be base 31 but is generally acceptable
unless you want to start worrying about stuff like "SH1T". Maybe
another approach would be to construct a table of the smallish set of
unacceptable numbers and check against that each time.
Here's a generalised function for converting integers to a number base
defined by any character set:
CREATE FUNCTION dbo.IntToBase(@.i INTEGER, @.base_charset VARCHAR(256))
RETURNS CHAR(4)
AS
BEGIN
DECLARE @.b TINYINT, @.d1 TINYINT, @.d2 TINYINT, @.d3 TINYINT, @.d4 TINYINT
SELECT
@.b = LEN(@.base_charset),
@.d1 = FLOOR(@.i/@.b*@.b*@.b)%@.b,
@.d2 = FLOOR(@.i/@.b*@.b)%@.b,
@.d3 = FLOOR(@.i/@.b)%@.b,
@.d4 = @.i%@.b
RETURN
SUBSTRING(@.base_charset,@.d1+1,1)+
SUBSTRING(@.base_charset,@.d2+1,1)+
SUBSTRING(@.base_charset,@.d3+1,1)+
SUBSTRING(@.base_charset,@.d4+1,1)
END
GO
/* Base 31 characters */
SELECT dbo. IntToBase(1234,'0123456789BCDFGHJKLMNPQR
STVWXYZ');
/* Base 16 characters */
SELECT dbo.IntToBase(1234,'0123456789ABCDEF');
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Oops. That wasn't very well tested. Here's a correction:
CREATE FUNCTION dbo.IntToBase(@.i INTEGER, @.base_charset VARCHAR(256))
RETURNS CHAR(4)
AS
BEGIN
DECLARE @.b TINYINT, @.d1 TINYINT, @.d2 TINYINT, @.d3 TINYINT, @.d4 TINYINT
SELECT
@.b = LEN(@.base_charset),
@.d1 = FLOOR(@.i/@.b/@.b/@.b)%@.b,
@.d2 = FLOOR(@.i/@.b/@.b)%@.b,
@.d3 = FLOOR(@.i/@.b)%@.b,
@.d4 = @.i%@.b
RETURN
SUBSTRING(@.base_charset,@.d1+1,1)+
SUBSTRING(@.base_charset,@.d2+1,1)+
SUBSTRING(@.base_charset,@.d3+1,1)+
SUBSTRING(@.base_charset,@.d4+1,1)
END
GO
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||> To eliminate the offensive words why not just exclude vowels from the
> account numbers.
"And Serpent bringeth forth the vowel."
- Luke, 7-45
How about keeping a table of 'illegal' values? There can't be that many if
the string is only 4 characters long.
ML
http://milambda.blogspot.com/|||actually you're right. in fact, since the base value never goes above
2^31, the highest base32 value would be 4000, which means the first
digit never even gets to the letters. so now we're just talking about
three letter offensive words. of course we'd have to worry about
homophones too, like FUK. i'm not sure which would be easier, but i'll
consider both.|||oh wow, so i could essentially create my own notation that has no
vowels. i didn't realize that was even going to be an option, but hell
yeah, that seriously makes the offensive word thing a lot easier!
and yeah, we considered the 'leet' curse word issue, but decided that's
just too annoying to worry about. if someone gets account number SH1T,
and doesn't chuckle, then we can survive the loss.
thanks!
jason|||"jason" <iaesun@.yahoo.com> wrote in message
news:1138387792.331310.253560@.g43g2000cwa.googlegroups.com...
> actually you're right. in fact, since the base value never goes above
> 2^31, the highest base32 value would be 4000, which means the first
> digit never even gets to the letters. so now we're just talking about
> three letter offensive words. of course we'd have to worry about
> homophones too, like FUK. i'm not sure which would be easier, but i'll
> consider both.
ASS
FAG
KKK
and of course, the most offensive one of all... :-)
DBA|||FYI
Actually, the word "fuk" has that same meaning in several other languages.
Of course it's pronounced differently.
Maybe there already is a list of offensive words available somewhere.
http://en.wikipedia.org/wiki/Seven_dirty_words
ML
http://milambda.blogspot.com/|||> and of course, the most offensive one of all... :-)
> DBA
You forgot:
DEV
:)
ML
http://milambda.blogspot.com/|||hey David,
thanks, this function looks pretty versatile. i'm having an
implementation problem with it though. when i run it against the
existing list of account numbers, i'm getting a looping result. int
value 2147186326 is coming out as '0001' in base31 notation, which is
the same value that the int value 1. i thought perhaps that base31
couldn't store an int in only 4 digits, and this was a truncation
problem, so i tried to extrapolate the function to return base x
digits, but that didn't actually change the behavior, there was still a
notation wrap at 2147186326, so i'm sure i didn't modify it correctly.
just thought i'd run it by you to see if you had any ideas?
thanks again,
jason

Friday, February 24, 2012

C# MSSQL - number of recordsets

Hi,
I've got a problem which might be a little bit tricky.
I need to find out if selected stored procedure can return more than
one recordset at execution. I know that that might depend on the
parameter values, but it will be perfect if it would be possible just
to count select statements within the procedure code that are actually
return as a recordsets. Following my idea the following procedure
returns 2 recordsets (it isn't i know, but taht will be much easier to
do and that's fine by me so).
Any help will be appreciated.
CREATE PROCEDURE SP_TEST_PROCEDURE
@.PARAM1 INT
AS
BEGIN
IF @.PARAM1 = 1
BEGIN
SELECT * FROM PUBS..SALES
END
IF @.PARAM1 = 2
BEGIN
SELECT * FROM PUBS..JOBS
END
IF @.PARAM1 = 3
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
END
Yes, a stored procedure can return multiple resultsets.
For example, using your test code.
CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
( @.Param1 INT )
AS
BEGIN
IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..SALES
END
IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..JOBS
END
IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
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
<sajberek@.gmail.com> wrote in message news:1164837566.847747.152580@.16g2000cwy.googlegro ups.com...
> Hi,
> I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
> CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 = 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 = 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 = 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>
|||Yes, a stored procedure can return multiple resultsets.
For example, using your test code.
CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
( @.Param1 INT )
AS
BEGIN
IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..SALES
END
IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..JOBS
END
IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
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
<sajberek@.gmail.com> wrote in message news:1164837566.847747.152580@.16g2000cwy.googlegro ups.com...
> Hi,
> I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
> CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 = 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 = 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 = 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>
|||Yes I know, but how to count how many of them can it return at once?
On 30 Lis, 05:05, "Arnie Rowland" <a...@.1568.com> wrote:[vbcol=seagreen]
> Yes, a stored procedure can return multiple resultsets.
> For example, using your test code.
> CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
> ( @.Param1 INT )
> AS
> BEGIN
> IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
> EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
> --
> 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
>
> <sajbe...@.gmail.com> wrote in messagenews:1164837566.847747.152580@.16g2000cwy.go oglegroups.com...
>
|||Hi there,
Now, obviously I dont know the particulars and there could be a good
reason as to why you need to do this but its seems like quite a messy
solution.
Are you sure there's no other way to do what your attempting to do?
Perhaps you could use C# to build up dynamic SQL and submit it to the
stored procedure. It would be much easier to figure out how many RS
you're getting back if you built the sql in C#. It could be that you
can't actually do it this way though.
If you need a hand submitting dynamic sql to an SPROC then let me know.
My general advice would be to find another way of what you're doing.
Kindest Regards
Simon
|||If you want to know how many it 'can' return, then it seems that is
something you should know when you write the code.
If you want to know how many it 'did' (not counting empty sets) return, you
could easily accumulate an output parameter after checking the @.@.ROWCOUNT.
Otherwise, you request just doesn't make sense.
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
<sajberek@.gmail.com> wrote in message
news:1164870186.154846.289960@.l39g2000cwd.googlegr oups.com...
Yes I know, but how to count how many of them can it return at once?
On 30 Lis, 05:05, "Arnie Rowland" <a...@.1568.com> wrote:[vbcol=seagreen]
> Yes, a stored procedure can return multiple resultsets.
> For example, using your test code.
> CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
> ( @.Param1 INT )
> AS
> BEGIN
> IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
> EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
> --
> 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
>
> <sajbe...@.gmail.com> wrote in
> messagenews:1164837566.847747.152580@.16g2000cwy.go oglegroups.com...
>
|||Unless you can correctly parse T-SQL, you can't just count the number of
SELECT to determine the number of resultsets. Consider the cases with
subqueries and SELECT can be arbitrarily nested within other SELECT's.
Linchi
"sajberek@.gmail.com" wrote:

> Hi,
> I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
> CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 = 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 = 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 = 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>

C# MSSQL - number of recordsets

Hi,
I've got a problem which might be a little bit tricky.
I need to find out if selected stored procedure can return more than
one recordset at execution. I know that that might depend on the
parameter values, but it will be perfect if it would be possible just
to count select statements within the procedure code that are actually
return as a recordsets. Following my idea the following procedure
returns 2 recordsets (it isn't i know, but taht will be much easier to
do and that's fine by me so).
Any help will be appreciated.
CREATE PROCEDURE SP_TEST_PROCEDURE
@.PARAM1 INT
AS
BEGIN
IF @.PARAM1 = 1
BEGIN
SELECT * FROM PUBS..SALES
END
IF @.PARAM1 = 2
BEGIN
SELECT * FROM PUBS..JOBS
END
IF @.PARAM1 = 3
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
ENDThis is a multi-part message in MIME format.
--=_NextPart_000_0297_01C713F1.B92E3DD0
Content-Type: text/plain;
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
Yes, a stored procedure can return multiple resultsets.
For example, using your test code.
CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
( @.Param1 INT )
AS
BEGIN
IF ( @.Param1 =3D 1 ) OR ( @.Param1 =3D 4 )
BEGIN
SELECT * FROM PUBS..SALES
END
IF ( @.Param1 =3D 2 ) OR ( @.Param1 =3D 4 )
BEGIN
SELECT * FROM PUBS..JOBS
END
IF ( @.Param1 =3D 3 ) OR ( @.Param1 =3D 4 )
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT =3D 4
-- 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
<sajberek@.gmail.com> wrote in message =news:1164837566.847747.152580@.16g2000cwy.googlegroups.com...
> Hi,
> > I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
> > CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 =3D 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 =3D 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 =3D 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>
--=_NextPart_000_0297_01C713F1.B92E3DD0
Content-Type: text/html;
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Yes, a stored procedure can return =multiple resultsets.
For example, using your test =code.
CREATE =PROCEDURE dbo.SP_TEST_PROCEDURE ( @.Param1 INT =)AS BEGIN IF ( @.Param1 =3D 1 ) OR ( =@.Param1 =3D 4 ) BEGIN &nbs=p; SELECT * FROM =PUBS..SALES END IF ( @.Param1 =3D 2 ) OR ( @.Param1 ==3D 4 ) BEGIN &nbs=p; SELECT * FROM =PUBS..JOBS END IF ( @.Param1 =3D 3 ) OR ( @.Param1 ==3D 4 ) BEGIN &nbs=p; SELECT * INTO #TEST_TABLE FROM PUBS.JOBS END END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT =3D 4
-- 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:1164837566.847747.152580@.16g2000cwy.googlegroups.com=...> =Hi,> > I've got a problem which might be a little bit tricky.> =I need to find out if selected stored procedure can return more than> =one recordset at execution. I know that that might depend on the> =parameter values, but it will be perfect if it would be possible just> to =count select statements within the procedure code that are actually> =return as a recordsets. Following my idea the following procedure> returns =2 recordsets (it isn't i know, but taht will be much easier to> do =and that's fine by me so).> Any help will be appreciated.> => CREATE PROCEDURE SP_TEST_PROCEDURE> @.PARAM1 INT> =AS> BEGIN> IF @.PARAM1 =3D 1> BEGIN> SELECT * FROM PUBS..SALES> END> IF @.PARAM1 =3D 2> BEGIN> SELECT =* FROM PUBS..JOBS> END> IF @.PARAM1 =3D 3> BEGIN> SELECT =* INTO #TEST_TABLE FROM PUBS.JOBS> END> END>

--=_NextPart_000_0297_01C713F1.B92E3DD0--|||This is a multi-part message in MIME format.
--=_NextPart_000_0297_01C713F1.B92E3DD0
Content-Type: text/plain;
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
Yes, a stored procedure can return multiple resultsets.
For example, using your test code.
CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
( @.Param1 INT )
AS
BEGIN
IF ( @.Param1 =3D 1 ) OR ( @.Param1 =3D 4 )
BEGIN
SELECT * FROM PUBS..SALES
END
IF ( @.Param1 =3D 2 ) OR ( @.Param1 =3D 4 )
BEGIN
SELECT * FROM PUBS..JOBS
END
IF ( @.Param1 =3D 3 ) OR ( @.Param1 =3D 4 )
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT =3D 4
-- 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
<sajberek@.gmail.com> wrote in message =news:1164837566.847747.152580@.16g2000cwy.googlegroups.com...
> Hi,
> > I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
> > CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 =3D 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 =3D 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 =3D 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>
--=_NextPart_000_0297_01C713F1.B92E3DD0
Content-Type: text/html;
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Yes, a stored procedure can return =multiple resultsets.
For example, using your test =code.
CREATE =PROCEDURE dbo.SP_TEST_PROCEDURE ( @.Param1 INT =)AS BEGIN IF ( @.Param1 =3D 1 ) OR ( =@.Param1 =3D 4 ) BEGIN &nbs=p; SELECT * FROM =PUBS..SALES END IF ( @.Param1 =3D 2 ) OR ( @.Param1 ==3D 4 ) BEGIN &nbs=p; SELECT * FROM =PUBS..JOBS END IF ( @.Param1 =3D 3 ) OR ( @.Param1 ==3D 4 ) BEGIN &nbs=p; SELECT * INTO #TEST_TABLE FROM PUBS.JOBS END END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT =3D 4
-- 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:1164837566.847747.152580@.16g2000cwy.googlegroups.com=...> =Hi,> > I've got a problem which might be a little bit tricky.> =I need to find out if selected stored procedure can return more than> =one recordset at execution. I know that that might depend on the> =parameter values, but it will be perfect if it would be possible just> to =count select statements within the procedure code that are actually> =return as a recordsets. Following my idea the following procedure> returns =2 recordsets (it isn't i know, but taht will be much easier to> do =and that's fine by me so).> Any help will be appreciated.> => CREATE PROCEDURE SP_TEST_PROCEDURE> @.PARAM1 INT> =AS> BEGIN> IF @.PARAM1 =3D 1> BEGIN> SELECT * FROM PUBS..SALES> END> IF @.PARAM1 =3D 2> BEGIN> SELECT =* FROM PUBS..JOBS> END> IF @.PARAM1 =3D 3> BEGIN> SELECT =* INTO #TEST_TABLE FROM PUBS.JOBS> END> END>

--=_NextPart_000_0297_01C713F1.B92E3DD0--|||Yes I know, but how to count how many of them can it return at once?
On 30 Lis, 05:05, "Arnie Rowland" <a...@.1568.com> wrote:
> Yes, a stored procedure can return multiple resultsets.
> For example, using your test code.
> CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
> ( @.Param1 INT )
> AS
> BEGIN
> IF ( @.Param1 =3D 1 ) OR ( @.Param1 =3D 4 )
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF ( @.Param1 =3D 2 ) OR ( @.Param1 =3D 4 )
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF ( @.Param1 =3D 3 ) OR ( @.Param1 =3D 4 )
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
> EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT =3D 4
> --
> 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 t=he top yourself.
> - H. Norman Schwarzkopf
>
> <sajbe...@.gmail.com> wrote in messagenews:1164837566.847747.152580@.16g200=0cwy.googlegroups.com...
> > Hi,
> > I've got a problem which might be a little bit tricky.
> > I need to find out if selected stored procedure can return more than
> > one recordset at execution. I know that that might depend on the
> > parameter values, but it will be perfect if it would be possible just
> > to count select statements within the procedure code that are actually
> > return as a recordsets. Following my idea the following procedure
> > returns 2 recordsets (it isn't i know, but taht will be much easier to
> > do and that's fine by me so).
> > Any help will be appreciated.
> > CREATE PROCEDURE SP_TEST_PROCEDURE
> > @.PARAM1 INT
> > AS
> > BEGIN
> > IF @.PARAM1 =3D 1
> > BEGIN
> > SELECT * FROM PUBS..SALES
> > END
> > IF @.PARAM1 =3D 2
> > BEGIN
> > SELECT * FROM PUBS..JOBS
> > END
> > IF @.PARAM1 =3D 3
> > BEGIN
> > SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> > END
> > END- Ukryj cytowany tekst -- Poka=BF cytowany tekst -|||Hi there,
Now, obviously I dont know the particulars and there could be a good
reason as to why you need to do this but its seems like quite a messy
solution.
Are you sure there's no other way to do what your attempting to do?
Perhaps you could use C# to build up dynamic SQL and submit it to the
stored procedure. It would be much easier to figure out how many RS
you're getting back if you built the sql in C#. It could be that you
can't actually do it this way though.
If you need a hand submitting dynamic sql to an SPROC then let me know.
My general advice would be to find another way of what you're doing.
Kindest Regards
Simon|||If you want to know how many it 'can' return, then it seems that is
something you should know when you write the code.
If you want to know how many it 'did' (not counting empty sets) return, you
could easily accumulate an output parameter after checking the @.@.ROWCOUNT.
Otherwise, you request just doesn't make sense.
--
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
<sajberek@.gmail.com> wrote in message
news:1164870186.154846.289960@.l39g2000cwd.googlegroups.com...
Yes I know, but how to count how many of them can it return at once?
On 30 Lis, 05:05, "Arnie Rowland" <a...@.1568.com> wrote:
> Yes, a stored procedure can return multiple resultsets.
> For example, using your test code.
> CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
> ( @.Param1 INT )
> AS
> BEGIN
> IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
> EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
> --
> 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
>
> <sajbe...@.gmail.com> wrote in
> messagenews:1164837566.847747.152580@.16g2000cwy.googlegroups.com...
> > Hi,
> > I've got a problem which might be a little bit tricky.
> > I need to find out if selected stored procedure can return more than
> > one recordset at execution. I know that that might depend on the
> > parameter values, but it will be perfect if it would be possible just
> > to count select statements within the procedure code that are actually
> > return as a recordsets. Following my idea the following procedure
> > returns 2 recordsets (it isn't i know, but taht will be much easier to
> > do and that's fine by me so).
> > Any help will be appreciated.
> > CREATE PROCEDURE SP_TEST_PROCEDURE
> > @.PARAM1 INT
> > AS
> > BEGIN
> > IF @.PARAM1 = 1
> > BEGIN
> > SELECT * FROM PUBS..SALES
> > END
> > IF @.PARAM1 = 2
> > BEGIN
> > SELECT * FROM PUBS..JOBS
> > END
> > IF @.PARAM1 = 3
> > BEGIN
> > SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> > END
> > END- Ukryj cytowany tekst -- Poka¿ cytowany tekst -

C# MSSQL - number of recordsets

Hi,
I've got a problem which might be a little bit tricky.
I need to find out if selected stored procedure can return more than
one recordset at execution. I know that that might depend on the
parameter values, but it will be perfect if it would be possible just
to count select statements within the procedure code that are actually
return as a recordsets. Following my idea the following procedure
returns 2 recordsets (it isn't i know, but taht will be much easier to
do and that's fine by me so).
Any help will be appreciated.
CREATE PROCEDURE SP_TEST_PROCEDURE
@.PARAM1 INT
AS
BEGIN
IF @.PARAM1 = 1
BEGIN
SELECT * FROM PUBS..SALES
END
IF @.PARAM1 = 2
BEGIN
SELECT * FROM PUBS..JOBS
END
IF @.PARAM1 = 3
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
ENDYes, a stored procedure can return multiple resultsets.
For example, using your test code.
CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
( @.Param1 INT )
AS
BEGIN
IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..SALES
END
IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..JOBS
END
IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
--
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
<sajberek@.gmail.com> wrote in message news:1164837566.847747.152580@.16g2000cwy.googlegroups.
com...
> Hi,
>
> I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
>
> CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 = 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 = 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 = 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>|||Yes, a stored procedure can return multiple resultsets.
For example, using your test code.
CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
( @.Param1 INT )
AS
BEGIN
IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..SALES
END
IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * FROM PUBS..JOBS
END
IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
BEGIN
SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
END
END
EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
--
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
<sajberek@.gmail.com> wrote in message news:1164837566.847747.152580@.16g2000cwy.googlegroups.
com...
> Hi,
>
> I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
>
> CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 = 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 = 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 = 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>|||Yes I know, but how to count how many of them can it return at once?
On 30 Lis, 05:05, "Arnie Rowland" <a...@.1568.com> wrote:
> Yes, a stored procedure can return multiple resultsets.
> For example, using your test code.
> CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
> ( @.Param1 INT )
> AS
> BEGIN
> IF ( @.Param1 =3D 1 ) OR ( @.Param1 =3D 4 )
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF ( @.Param1 =3D 2 ) OR ( @.Param1 =3D 4 )
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF ( @.Param1 =3D 3 ) OR ( @.Param1 =3D 4 )
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
> EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT =3D 4
> --
> 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 t=
he top yourself.
> - H. Norman Schwarzkopf
>
> <sajbe...@.gmail.com> wrote in messagenews:1164837566.847747.152580@.16g200=
0cwy.googlegroups.com...[vbcol=seagreen]
>
>|||Hi there,
Now, obviously I dont know the particulars and there could be a good
reason as to why you need to do this but its seems like quite a messy
solution.
Are you sure there's no other way to do what your attempting to do?
Perhaps you could use C# to build up dynamic SQL and submit it to the
stored procedure. It would be much easier to figure out how many RS
you're getting back if you built the sql in C#. It could be that you
can't actually do it this way though.
If you need a hand submitting dynamic sql to an SPROC then let me know.
My general advice would be to find another way of what you're doing.
Kindest Regards
Simon|||If you want to know how many it 'can' return, then it seems that is
something you should know when you write the code.
If you want to know how many it 'did' (not counting empty sets) return, you
could easily accumulate an output parameter after checking the @.@.ROWCOUNT.
Otherwise, you request just doesn't make sense.
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
<sajberek@.gmail.com> wrote in message
news:1164870186.154846.289960@.l39g2000cwd.googlegroups.com...
Yes I know, but how to count how many of them can it return at once?
On 30 Lis, 05:05, "Arnie Rowland" <a...@.1568.com> wrote:[vbcol=seagreen]
> Yes, a stored procedure can return multiple resultsets.
> For example, using your test code.
> CREATE PROCEDURE dbo.SP_TEST_PROCEDURE
> ( @.Param1 INT )
> AS
> BEGIN
> IF ( @.Param1 = 1 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF ( @.Param1 = 2 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF ( @.Param1 = 3 ) OR ( @.Param1 = 4 )
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
> EXECUTE dbo.SP_TEST_PROCEDURE @.Param1 INT = 4
> --
> 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
>
> <sajbe...@.gmail.com> wrote in
> messagenews:1164837566.847747.152580@.16g2000cwy.googlegroups.com...
>
>|||Unless you can correctly parse T-SQL, you can't just count the number of
SELECT to determine the number of resultsets. Consider the cases with
subqueries and SELECT can be arbitrarily nested within other SELECT's.
Linchi
"sajberek@.gmail.com" wrote:

> Hi,
> I've got a problem which might be a little bit tricky.
> I need to find out if selected stored procedure can return more than
> one recordset at execution. I know that that might depend on the
> parameter values, but it will be perfect if it would be possible just
> to count select statements within the procedure code that are actually
> return as a recordsets. Following my idea the following procedure
> returns 2 recordsets (it isn't i know, but taht will be much easier to
> do and that's fine by me so).
> Any help will be appreciated.
> CREATE PROCEDURE SP_TEST_PROCEDURE
> @.PARAM1 INT
> AS
> BEGIN
> IF @.PARAM1 = 1
> BEGIN
> SELECT * FROM PUBS..SALES
> END
> IF @.PARAM1 = 2
> BEGIN
> SELECT * FROM PUBS..JOBS
> END
> IF @.PARAM1 = 3
> BEGIN
> SELECT * INTO #TEST_TABLE FROM PUBS.JOBS
> END
> END
>

Sunday, February 19, 2012

C

Hi,

I have a bit of code written in class ASP that connects to a database with Command.Execute. It works fine with SQL 2000 but after an upgrade to SQL 2005 causes the asp page to hang while w3wp runs at at 100%

I'm running SQL 2005 SP1 on the same machine as IIS. I can't see anything in the event log or the SQL logs that would explain this (no errors in either). SQL profiler shows the stored procedure is called.

The code is below. Does anyone know of anything that might be causing this. I've spent two days so far trying to find a cause. The ODBC connection SDB1 is using SQL Native Client.

MyConn.Open "DSN=SDB1;Initial Catalog=database","username","password"

Set MyCommand.ActiveConnection=MyConn
MyCommand.CommandType = adCmdStoredProc
MyCommand.CommandText = "[owner].[procname]"
Set MyParam=MyCommand.CreateParameter("in_ip",adVarChar,adParamInput,10)
MyCommand.Parameters.Append MyParam
Set MyResult=MyCommand.CreateParameter("ip_country",adVarChar,adParamOutput,50)
MyCommand.Parameters.Append MyResult

MyCommand.Execute

Can anyone shed any light on this?

For anybody elses reference, I have found the cause of this.

The database user had connect permission but nothing else. This meant the user could connect to the database but not select/update or delete. Giving it the necessary rights solved the problem.

However, why this was causing IIS to run at 100% is still a mystery.

Regards,

Mark.

bytes used by datatypes

Where can i find how much bytes datatypes such as
int,datetime,money,bit,varchar consume ?
Thanks
Check BOL
Books Online...
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and time
asking back if its 2000 or 2005]
"Hassan" wrote:

> Where can i find how much bytes datatypes such as
> int,datetime,money,bit,varchar consume ?
> Thanks
>
>
|||Check SQL Server Books Online
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
"Hassan" <Hassan@.hotmail.com> wrote in message
news:u9T5xLLQGHA.3192@.TK2MSFTNGP09.phx.gbl...
> Where can i find how much bytes datatypes such as
> int,datetime,money,bit,varchar consume ?
> Thanks
>
|||Look at Data Types in books online
Regards
Amish shah
Jack Vamvas wrote:
[vbcol=seagreen]
> Check SQL Server Books Online
> --
> Jack Vamvas
> ___________________________________
> Receive free SQL tips - www.ciquery.com/sqlserver.htm
> "Hassan" <Hassan@.hotmail.com> wrote in message
> news:u9T5xLLQGHA.3192@.TK2MSFTNGP09.phx.gbl...

bytes used by datatypes

Where can i find how much bytes datatypes such as
int,datetime,money,bit,varchar consume ?
ThanksCheck BOL
Books Online...
--
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and
time
asking back if its 2000 or 2005]
"Hassan" wrote:

> Where can i find how much bytes datatypes such as
> int,datetime,money,bit,varchar consume ?
> Thanks
>
>|||Check SQL Server Books Online
--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
"Hassan" <Hassan@.hotmail.com> wrote in message
news:u9T5xLLQGHA.3192@.TK2MSFTNGP09.phx.gbl...
> Where can i find how much bytes datatypes such as
> int,datetime,money,bit,varchar consume ?
> Thanks
>|||Look at Data Types in books online
Regards
Amish shah
Jack Vamvas wrote:
[vbcol=seagreen]
> Check SQL Server Books Online
> --
> Jack Vamvas
> ___________________________________
> Receive free SQL tips - www.ciquery.com/sqlserver.htm
> "Hassan" <Hassan@.hotmail.com> wrote in message
> news:u9T5xLLQGHA.3192@.TK2MSFTNGP09.phx.gbl...

bytes used by datatypes

Where can i find how much bytes datatypes such as
int,datetime,money,bit,varchar consume ?
ThanksCheck BOL
Books Online...
--
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and time
asking back if its 2000 or 2005]
"Hassan" wrote:
> Where can i find how much bytes datatypes such as
> int,datetime,money,bit,varchar consume ?
> Thanks
>
>|||Check SQL Server Books Online
--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
"Hassan" <Hassan@.hotmail.com> wrote in message
news:u9T5xLLQGHA.3192@.TK2MSFTNGP09.phx.gbl...
> Where can i find how much bytes datatypes such as
> int,datetime,money,bit,varchar consume ?
> Thanks
>|||Look at Data Types in books online
Regards
Amish shah
Jack Vamvas wrote:
> Check SQL Server Books Online
> --
> Jack Vamvas
> ___________________________________
> Receive free SQL tips - www.ciquery.com/sqlserver.htm
> "Hassan" <Hassan@.hotmail.com> wrote in message
> news:u9T5xLLQGHA.3192@.TK2MSFTNGP09.phx.gbl...
> > Where can i find how much bytes datatypes such as
> > int,datetime,money,bit,varchar consume ?
> >
> > Thanks
> >
> >

Sunday, February 12, 2012

Business Day Calendar table get x days in the past

I have a table of dates and a second column for bit. I need to know the
date of X business days ago
declare @.dateIn datetime, @.days int
set @.datein = '5-17-2006'
set @.days=5
select A.bdate
From BusinessCALendar as A
Inner Join BusinessCALendar as B
on A.bdate <= B.bdate
and A.btype=B.btype
Where A.btype= 1 -- identify a work day as 1
and A.bdate < @.datein
Group by A.bdate
Having count(*) = @.days
My having line voids any return of data. I think this is close, but how do
you walk backwards in rows?
TIAhttp://www.aspfaq.com/2519
"_Stephen" <srussell@.electracash.com> wrote in message
news:OBe6%23oceGHA.4532@.TK2MSFTNGP02.phx.gbl...
>I have a table of dates and a second column for bit. I need to know the
>date of X business days ago
> declare @.dateIn datetime, @.days int
> set @.datein = '5-17-2006'
> set @.days=5
> select A.bdate
> From BusinessCALendar as A
> Inner Join BusinessCALendar as B
> on A.bdate <= B.bdate
> and A.btype=B.btype
> Where A.btype= 1 -- identify a work day as 1
> and A.bdate < @.datein
> Group by A.bdate
> Having count(*) = @.days
>
> My having line voids any return of data. I think this is close, but how
> do you walk backwards in rows?
>
> TIA
>|||http://www.aspfaq.com/2519
"_Stephen" <srussell@.electracash.com> wrote in message
news:OBe6%23oceGHA.4532@.TK2MSFTNGP02.phx.gbl...
>I have a table of dates and a second column for bit. I need to know the
>date of X business days ago
> declare @.dateIn datetime, @.days int
> set @.datein = '5-17-2006'
> set @.days=5
> select A.bdate
> From BusinessCALendar as A
> Inner Join BusinessCALendar as B
> on A.bdate <= B.bdate
> and A.btype=B.btype
> Where A.btype= 1 -- identify a work day as 1
> and A.bdate < @.datein
> Group by A.bdate
> Having count(*) = @.days
>
> My having line voids any return of data. I think this is close, but how
> do you walk backwards in rows?
>
> TIA
>|||> http://www.aspfaq.com/2519
Thanks. I got what was needed there.