|
I believe you're looking for something like the following:
USE AdventureWorks
GO
SELECT VendorID, [164] AS Emp1, [198] AS Emp2, [223] AS Emp3, [231] AS Emp4, [233] AS Emp5
FROM
(SELECT PurchaseOrderID, EmployeeID, VendorID
FROM Purchasing.PurchaseOrderHeader) AS p
PIVOT
(
COUNT (PurchaseOrderID)
FOR EmployeeID IN
( [164], [198], [223], [231], [233] )
) AS pvt
ORDER BY VendorID;
"My interest is in the future because I'm going to spend the rest of my life there." - Charles F. Kettering
|
|
|
|
|
This may help Pivot article[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have set the EMP_ID column in my database as the Primary Key. I mean this is the primary key column. And when I try to insert values in my database table from the form in then it gives me an error as:
"Cannot insert explicit value for identity column in table 'Employees' when IDENTITY_INSERT is set to OFF."
So, how is the IDENTITY_INSERT set to on. Where it is actually located so that I can modify it and start to insert values into my table.
Moreover, when I remove the primary key from this column(EMP_ID) and uncheck the Allow Nulls checkbox then also my same problem persists.
Kindly help me out. I am currently using SQL Server 2005.
|
|
|
|
|
it depends on what you want to do. if you want to enable insertion on identity column
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON | OFF } otherwise remove identity from the emp_id column and insert the value from field
|
|
|
|
|
sorry typo error i mean form not field
|
|
|
|
|
I think you are trying to insert a value into a identity column. If you are inserting the value into intentionally then you have to set Identity_insert tablename on/off. else ignore this column while inserting, sql server automatically inserts records into this field.
|
|
|
|
|
If you have access to the Management Studio of SQL Server, try and check the property for the column of your table in design mode, check the Identity Specification property...
|
|
|
|
|
There is a table called QCR100 containing the following information
ITEM_CODE ITEM_DESCRIPTION DCODE AMOUNT
111200 investments 24000003 1630000000.0000
111200 investments 126000005 1630000000.0000
111600 Other Assets 133000009 1700000000.0000
111600 Other Assets 150000002 1730000000.0000
111701 Leasehold 190010130 1740000000.0000
111705 Furniture 190010036 1750000000.0000
111706 Computer Software 190010141 46995799.1800
Then I created a view with this command statement:
SELECT CASE WHEN LEFT(e.dcode, 1) = '1' THEN isnull(SUM(a.Dr_bal_lcy - a.CR_BAL_LCY), 0) WHEN LEFT(e.dcode, 1)
= '2' THEN isnull(SUM(a.CR_BAL_LCY - a.Dr_bal_lcy), 0) ELSE 0 END AS amount, e.ITEM_DESCRIPTION, e.ITEM_CODE
FROM dbo.GLTEMP_CONS AS a RIGHT OUTER JOIN
dbo.QCR100 AS e ON LTRIM(a.GL_code) = e.Dcode
GROUP BY e.ITEM_DESCRIPTION, e.ITEM_CODE, e.Dcode
How I can alter this view to sum the amount for any duplicated item code and group by item code
Example
ITEM_CODE ITEM_DESCRIPTION DCODE AMOUNT
111200 investments 24000003 1630000000.0000
111600 Other Assets 133000009 1700000000.0000
111701 Leasehold 190010130 1740000000.0000
111705 Furniture 190010036 1750000000.0000
111706 Computer Software 190010141 46995799.1800
|
|
|
|
|
Hope you are lloking for this query.
select item_code,ITEM_DESCRIPTION,<br />
(select max(t1.dcode) from qcr100 as t1 where t1.item_code=qcr100.item_code) as dcode,<br />
sum(cast(amount as float)) as amount<br />
from qcr100 <br />
group by item_code,ITEM_DESCRIPTION
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
actually i can write sql statement to do that. in fact i written it as another view call qcr100f because i will use it to update anorher table. but i want to improve on this giving that the gl_temp_cons has schema
idkey db_bal cr_bal dcode
i want to be able to get the result i post above in with one view definition
thanks for your concern
|
|
|
|
|
I have a customer who refuses to move from an old version of Great Plains 'pre-microsoft' on a novell server using Btrieve 6.15. I am looking for help/advice to make a small VB app that will let them query and print a listing from a specific DAT file. This is being done on a local copy of the data 'not live' on an XP machine. While not new to Vb, I only use it to play and relax 'just don't have the time any more'. I will be using VB 2008 and I guess I need help with the following:
1. What files will I need for the connection to this type of data?
2. What would the connection string look like.
I think those should be my only problems.
Thanks in advance and all help is greatly appriciated.
|
|
|
|
|
Try connectionstrings.com
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi
I am facing an issue in page break when the report is rendered as web archive in SSRS. I have applied PageBreak for the report on a group. This page break is rendered correctly when I view the report in PDF but the page break doesnt come when rendered in Web Archive.
Is there any way to apply Page Break to web archive?? I cant use InteractiveHeight for the pagebreak.
Please help ...
Thanks.
sanky
|
|
|
|
|
I don't know about SSRS, but a webarchive is in fact just a webpage. It's kinda difficult to put a page-break in a webpage, but this[^] site might help.
Good luck
|
|
|
|
|
i have this connection string in one of my applications but i got the famous
erro 40 . i tried many forums and found many suggestions but none of them could help!
string _connectionstring =
"server=" + Environment.MachineName +";Initial Catalog=myDatabase;"+
"user id=myLogin;password=myPassword;trusted_connection = true;";
please notice that this application works on local computer , not a network.
|
|
|
|
|
Open surface area configurations of SQL server and allow remote connections. It seems that you haven't enabled them up till now that's why network users can't connect to your database.
|
|
|
|
|
I am running the following MS ACCESS select command from a c# method.
SELECT USERINFO.USERID, CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE, DEPARTMENTS.DEPTNAME, USERINFO.NAME FROM (CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID) INNER JOIN DEPARTMENTS ON USERINFO.DEFAULTDEPTID = DEPARTMENTS.DEPTID WHERE CHECkINOUT.CHECKTIME BETWEEN @fromDate and @toDate " + sensors + "ORDER BY DEPARTMENTS.DEPTNAME;"
The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters
cmd.Parameters.AddWithValue("fromDate", todayDate);
cmd.Parameters.AddWithValue("toDate", tomorrowDate);
Can one identify why it is telling me ivalid criteria when the values should be dates?
|
|
|
|
|
jonhbt wrote: The problem is that the parameters that I am passing, which are in date format are throwing an ivalid criteria exception. This is how I am passing the parameters
cmd.Parameters.AddWithValue("fromDate", todayDate);
cmd.Parameters.AddWithValue("toDate", tomorrowDate);
You didn't use @ with the parameter.
Here is you modified code,
cmd.Parameters.AddWithValue("@fromDate", todayDate);
cmd.Parameters.AddWithValue("@toDate", tomorrowDate);
This will help you
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
It didn't work either it is showwing me the following error.
{System.Data.OleDb.OleDbException: Data type mismatch in criteria expression
|
|
|
|
|
If you step through the code and hover over todayDate and tomorrowDate what are there values?
|
|
|
|
|
Do you find any difficulties to use Add() Function,
cmd.Parameters.Add("@fromDate", SqlDbType.System.Data.SqlDbType.Date)
cmd.Parameters.Item(0).Value = todayDate;
Using Add() function you can avoid datatype conflicts here.
Education is not a way to escape poverty — it is a way of fighting it.
|
|
|
|
|
To explain the problem definition let me take a simple example. Lets say I have a report with Year as the parameter. So when i go to the report i have to select the year from a dropdownlist and click 'View report' button to view the report. assuming that for each year there are millons of records, I don't want to wait for long time for the report to show.
I know there is a caching and snapshot history features in SQL reporting services. But in both ways it would cache or save snapshot of report only for default value of parameter specified or for a particular report requested with selected parameter. It will not cache or snapshot for all possible parameter combinations. In my example i have taken only one parameter 'Year' and it may have lets say 10 values(2000-2009). But if i have another report with 'Year' and 'Month' parameters, then there would be 120 (10x12) possible reports combinations.
So my requirement is to some how(programatically or using web service or any other way) cache or snapshot all these possible reports using various combinations of parameters for a particular report.
Also would like to mention that the possible values for a parameter may also come from database. Like for 'Year' we might get the various values possible from a table in our database.
This requirement is so that user do not have to wait for long time when he requests a report with any parameter selected. This is to be done using SQL Reporting Services. Cheers!
s.a.w.
|
|
|
|
|
|
Can someone tell me what's wrong with this code? Basically the sp takes in one parameter and is creating a new record in tbl_swbom_checklist the values, with the package variable being set by the parameter, the rest being set by tbl_swbom_checklist_template entries.
CREATE PROCEDURE dbo.sp_CreateChecklistForPackage
(
@PACKAGE varchar(255)
)
AS
INSERT INTO TBL_SWBOM_CHECKLIST
(
PACKAGE,
TEMPLATEOWNER,
STEPNUMBER,
STEPNAME,
DESCRIPTION,
LASTCHANGE,
LASTCHANGEBY
)
values
(
@PACKAGE,
SELECT
TEMPLATEOWNER,
STEPNUMBER,
STEPNAME,
DESCRIPTION,
LASTCHANGE,
LASTCHANGEBY
FROM SWManagement.dbo.TBL_SWBOM_CHECKLIST_TEMPLATES
)
GO
|
|
|
|
|
Try this
INSERT INTO TBL_SWBOM_CHECKLIST
(
PACKAGE,
TEMPLATEOWNER,
STEPNUMBER,
STEPNAME,
DESCRIPTION,
LASTCHANGE,
LASTCHANGEBY
)
select
@PACKAGE,
TEMPLATEOWNER,
STEPNUMBER,
STEPNAME,
DESCRIPTION,
LASTCHANGE,
LASTCHANGEBY
FROM SWManagement.dbo.TBL_SWBOM_CHECKLIST_TEMPLATES
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|