Showing posts with label fields. Show all posts
Showing posts with label fields. Show all posts

Friday, March 30, 2012

Question relating Conversion and calculations

Hi,

I have couple of DBF files.. and when i get them into my scrub database the datatype for all the fields in char. but after i scrub the data i put them into a money feild.. so that if so that i can do any calculations that i want in the report...

Suppose if i keep as a char or varchar in my production database... is it possible to any calculation on it in my report.. just simple additions... and if yes... do i need to convert them into anything before doing the additions... The reason i am asking this is Some of the fields in the scrub database are empty and i want to keep them the same in my production database instead of showing 0.00 as a default.

Any help will be appreciated.

Regards

Karen

Hi,

From your description, it seems that you want make calculation on fields such as char typed in your database, right?

If so, I think you can achieve it by converting your fields in your stored procedure or select statement.
See the following sample, suppose we have two fields called Sp and Hd, which is nvarchar typed, now we can convert them into money typed and make calculation on them.

selectsum(convert(money,Hd))+sum(convert(money,Sp))As Totalfrom MatrixCapital

Thanks.

Monday, March 26, 2012

Question regarding connections with MSAccess

I have a Access 2002 (saved as 2K format) front end to a SQL Server (2000 I believe) and everything worked fine until I added 30 new fields to the main table. All of these fields are data type Bit and all are initialized to zero. I can add new records without any issues. The problem is that any time I try to update or delete a record I get the dreaded "Write Conflict..." msg in Access. If I use an older version of the system without refreshing the linked tables I have no problems. This behavior is also exhibited if I try to update/delete a record directly in the table so I know it is not something in my forms. Any help would be greatly appreciated.

Ron

The solution was to change the data type on the SQL Server to a 1 byte text field and poputate it programatically rather then having it directly bound to a control such as a checkbox. I never got a good answer as to why this was happening so I had to use the previously described workaround.

Question regarding connections with MSAccess

I have a Access 2002 (saved as 2K format) front end to a SQL Server (2000 I believe) and everything worked fine until I added 30 new fields to the main table. All of these fields are data type Bit and all are initialized to zero. I can add new records without any issues. The problem is that any time I try to update or delete a record I get the dreaded "Write Conflict..." msg in Access. If I use an older version of the system without refreshing the linked tables I have no problems. This behavior is also exhibited if I try to update/delete a record directly in the table so I know it is not something in my forms. Any help would be greatly appreciated.

Ron

The solution was to change the data type on the SQL Server to a 1 byte text field and poputate it programatically rather then having it directly bound to a control such as a checkbox. I never got a good answer as to why this was happening so I had to use the previously described workaround.sql

Question regarding calculated fields in reporting services 2005

Is there a concept of scope for calculated fields? I tried the
following and VS crashed.
=IIf(RowNumber("GroupName") = 1, MyValue, 0)
Example of what I am trying to accomplish.
GroupID, MyValue
1, 5
1, 5
1, 5
2, 10
3, 20
3, 20
========== Average MyValue should be (5 + 10 + 20)/3...not (5+5+5+10+20+20)/5.
MyValue would be the same for each GroupID. Does this make sense?Hi,
Infact you can use "Avg()" itself it has a scope parameter.
Amarnath
"Nergock@.gmail.com" wrote:
> Is there a concept of scope for calculated fields? I tried the
> following and VS crashed.
> =IIf(RowNumber("GroupName") = 1, MyValue, 0)
> Example of what I am trying to accomplish.
> GroupID, MyValue
> 1, 5
> 1, 5
> 1, 5
> 2, 10
> 3, 20
> 3, 20
> ==========> Average MyValue should be (5 + 10 + 20)/3...not (5+5+5+10+20+20)/5.
> MyValue would be the same for each GroupID. Does this make sense?
>

Tuesday, March 20, 2012

Question on repeated query

I have to select a number of fields for a report. Name Address, city,
state zip, etc. from a list of customers.
I have to select 2000 records from each of 29 states.
Is there a way to do this without repeating and repeating the code in
QA, or by changing the state manually and running it each time?
I have to select 2000 customers from WV, 2000 from VA, 2000 from FL,
2000 from TX and so on.
It's more of just a random selection of customers, with no other
requirements other than the name & address are a good one (i.e. non-null
last name, good zip code, etc).
Any help appreciated.Try,
select
Name Address, city, state, zip
from
t1 as a
where
customerid in (
select top 2000 customerid
from t1 as b
where b.state = a.state
)
go
If you run this query again, do not expect to pull same result because I am
not using "order by" clause.
AMB
"Blasting Cap" wrote:

> I have to select a number of fields for a report. Name Address, city,
> state zip, etc. from a list of customers.
> I have to select 2000 records from each of 29 states.
> Is there a way to do this without repeating and repeating the code in
> QA, or by changing the state manually and running it each time?
> I have to select 2000 customers from WV, 2000 from VA, 2000 from FL,
> 2000 from TX and so on.
> It's more of just a random selection of customers, with no other
> requirements other than the name & address are a good one (i.e. non-null
> last name, good zip code, etc).
> Any help appreciated.
>

Friday, March 9, 2012

question on how to form a query

I have a question on a query I hope it is not a dim question.
Table structure
Table name: Subscriptioncustomer
Fields: CustomerId - int , SubID - int, TypeId - smallint, date
- datetime, userid - varchar
Table Name: Customer
Fields: CustomerID - int, LastName- varchar. FirstName - varchar,
SSN - char
Table Name: Address
Field Name: AddressID-int, address - varchar
Table Name: Archived_Address
Field name: AddressID - int, CustomerID - int, TypeID - smallint,
active -bit
Question is I need to format the queries that will insert a new
customer for SubID 95122. Once you have the new CustomerID, tie the
customer to AddressID 854268 with another insertHi
Check out http://www.aspfaq.com/etiquette.asp?id=5006 on how to post DDL and
sample data in a form that will be useful to someone replying to a message.
If you make your ID columns identity values then you could use the
SCOPE_IDENTITY() function to return the ID you have just inserted.
You description is not clear what the Archived_Address is for maybe this
should be the linking table for Customer and Address?
Ignoring Archive_address, then if you had the following table definitions
CREATE TABLE Customer (
CustomerID INT NOT NULL IDENTITY(1,1) CONSTRAINT PK_Customer PRIMARY KEY
CLUSTERED,
LastName VARCHAR(128) NOT NULL,
FirstName VARCHAR(128) NOT NULL,
SSN CHAR(15) NULL )
CREATE TABLE Address (
AddressID INT NOT NULL IDENTITY(1,1) CONSTRAINT PK_Address PRIMARY KEY
CLUSTERED,
address VARCHAR(500) NOT NULL )
CREATE TABLE Subscriptioncustomer (
CustomerId INT NOT NULL,
SubID INT NOT NULL,
TypeId SMALLINT NOT NULL,
[date] DATETIME NOT NULL CONSTRAINT DF_date DEFAULT GETDATE(),
userid VARCHAR(128) NOT NULL CONSTRAINT DF_userid DEFAULT USER_ID(),
CONSTRAINT PK_Subscriptioncustomer PRIMARY KEY CLUSTERED (CustomerId, SubID),
CONSTRAINT FK_Subscriptioncustomer_Customer FOREIGN KEY (CustomerID)
REFERENCES Customer (CustomerID)
)
CREATE TABLE Archived_Address (
AddressID INT NOT NULL,
CustomerID INT NOT NULL,
TypeID SMALLINT NOT NULL,
active bit,
CONSTRAINT PK_Archived_Address PRIMARY KEY CLUSTERED
(AddressID,CustomerID,TypeID ),
CONSTRAINT FK_Archived_Address_Customer FOREIGN KEY (CustomerID) REFERENCES
Customer (CustomerID),
CONSTRAINT FK_Archived_Address_Address FOREIGN KEY (AddressID) REFERENCES
Address (AddressID)
)
You could use the following procedure to add a new customer, address for
that customer and a subscription.
CREATE PROCEDURE spr_New_Customer_and_Subscription ( @.LastName VARCHAR(128),
@.FirstName VARCHAR(128),
@.SSN CHAR(15),
@.address VARCHAR(500),
@.SubID INT,
@.TypeId INT )
AS
BEGIN
SET NOCOUNT ON
DECLARE @.customerid int
DECLARE @.addressid int
DECLARE @.stat int
BEGIN TRANSACTION
INSERT INTO Customer ( LastName, FirstName, SSN )
VALUES ( @.LastName, @.FirstName, @.SSN )
SELECT @.customerid = SCOPE_IDENTITY(), @.stat = @.@.ERROR
-- Add Error Checking
INSERT INTO Address ( address )
VALUES (@.address)
SELECT @.addressid = SCOPE_IDENTITY(), @.stat = @.@.ERROR
-- Add Error Checking
INSERT INTO Subscriptioncustomer (CustomerId, SubID, TypeId )
VALUES (@.CustomerId, @.SubID, @.TypeId )
SET @.stat = @.@.ERROR
-- Add Error Checking
COMMIT TRANSACTION
-- Rollback if previous error
END
-- Test Run
EXEC dbo.spr_New_Customer_and_Subscription @.LastName = 'Bell',
@.FirstName = 'John',
@.SSN = 'N/A',
@.address = 'Somewhere',
@.SubID = 1,
@.TypeId = 1
-- Check it worked
SELECT * FROM Customer
SELECT * FROM Address
SELECT * FROM Subscriptioncustomer
If you want to pass an existing AddressID change the parameters to the
procedure and remove the insert into the Address table.
HTH
John
"shismith123@.gmail.com" wrote:
> I have a question on a query I hope it is not a dim question.
> Table structure
> Table name: Subscriptioncustomer
> Fields: CustomerId - int , SubID - int, TypeId - smallint, date
> - datetime, userid - varchar
> Table Name: Customer
> Fields: CustomerID - int, LastName- varchar. FirstName - varchar,
> SSN - char
> Table Name: Address
> Field Name: AddressID-int, address - varchar
> Table Name: Archived_Address
> Field name: AddressID - int, CustomerID - int, TypeID - smallint,
> active -bit
> Question is I need to format the queries that will insert a new
> customer for SubID 95122. Once you have the new CustomerID, tie the
> customer to AddressID 854268 with another insert
>

Wednesday, March 7, 2012

Question on dynamic sorting

Hi,
I am trying to implement dynamic sorting using Reporting Services. I have 3
dropdowns on a page which contain the list of fields returned by a
stored procedure. What I am doing is creating the <Sorting> tag and its
children dynamically based on the sort the user selected. Then I am loading
the report definition (.rdl) into an Xml doc and I am adding the dynamically
created <Sorting> string to the doc at the appropriate location in the
document as if I had added sorting to the report using the Visual Studio IDE.
Then I turn the Xml doc into Byte[] and I am using this updated Byte[] array
to update the report definition. The problem is when I render the report
using the Render method, sorting does not take place as if the original .rdl
is used instead of the one I updated? Is there a way to dynamically deploy
the updated report definition? Is caching the culprit? Am I missing a step?
Is there a simpler way to implement dynamic sorting using RS?
Thanks muchyou could use the parameter "value" to drive the sorting for your table or
list. Under the sort properties, use =Fields(Parameters!SortBy.Value).Value
to have dynamic sorting.
"ISGADMIN" wrote:
> Hi,
> I am trying to implement dynamic sorting using Reporting Services. I have 3
> dropdowns on a page which contain the list of fields returned by a
> stored procedure. What I am doing is creating the <Sorting> tag and its
> children dynamically based on the sort the user selected. Then I am loading
> the report definition (.rdl) into an Xml doc and I am adding the dynamically
> created <Sorting> string to the doc at the appropriate location in the
> document as if I had added sorting to the report using the Visual Studio IDE.
> Then I turn the Xml doc into Byte[] and I am using this updated Byte[] array
> to update the report definition. The problem is when I render the report
> using the Render method, sorting does not take place as if the original .rdl
> is used instead of the one I updated? Is there a way to dynamically deploy
> the updated report definition? Is caching the culprit? Am I missing a step?
> Is there a simpler way to implement dynamic sorting using RS?
> Thanks much