Andy Tauber
Data Architect
The Vancouver Clinic
Website | LinkedIn
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.
Friday, October 31, 2014
How to query WCF webservice and pass a parameter
Month to Present and Year to Present Report
Hi Sbali,
For this we need to use subquery however it is difficult to write the query without having any DDL. Please provide sample data as well.
Regards, RSingh
Silent downloading with Webcontrol OR event to fire at end of download.
Silent downloading with Webcontrol OR event to fire at end of download.
I do not believe this to be true.
I inititate the download via the following statement
WebBrowser1.Document.GetElementById("GenerateFile").InvokeMember("click")
It does indeed begin a download.
How would you determine a filename given that all you know from the previous page is a button exists that can be clicked to initiate the download?
Absent that, please address the initial question.
Thank you.
Silent downloading with Webcontrol OR event to fire at end of download.
I do not believe this to be true.
This forum is not for religions, but it seems more that you want to click on a webpage to download from that data while nobody sees that.
There has spent billions by all kind of software builders to prevent that, so doing that is not easy. Also because code given for that can be used to create malicious code is it not a subject of the Microsoft forums, because with that we help persons who want to do that to find it easily.
Be aware that has not anything to do if your intent is malicious or not.
Success
Cor
How to disable a button when a time arrives?
Hello folks,
Could anyone please help me with a task? I have been thinking of it for some time now, but have no idea how to accomplish it.
I am using c# in VS 2008. I have a new requirement for a .NET application. Users have to enter information to a form every day. I need to know how to disable a button when the time arrives, e.g. let's say it is 10/30/2014 0.00 AM, the user can hit the button to save changes in the form until it is 10/30/2014 10.00PM. After that time, the button will be disabled so s/he won't be able to save changes. The button should be enabled again since 0.00 AM for the following date: 10/31/2014 and again, should be enabled until 10/31/2014 10.00 PM, and so on. For all dates before the current date the button must be disabled too.
Thank you very much for your help. I really appreciate it.
Marco
How to disable a button when a time arrives?
How to disable a button when a time arrives?
Thanks Nirosha for your quick answer.
I am trying to follow your sample, but I cannot find the .Stop() and .Start() methods for the timer. I used the timer which is in AJAX Extensions. Could you please let me know how I can use it?
Thank you very much,
Marco
SQL CASE STATEMENT IMPLEMENTATION
REquirment
• Add indicator to the end of the files, (position 1051 in both extracts, either have value of Y or N).
o DUAL COVERAGE (Y/N)
• Logic to determine indicator values from Member Eligibility Table:
o For ‘Y’ indicator:
o When dbo. CMC_MEPE_PRCS_ELIG.CSCS_ID = ‘MD11’ (Mean Dual covered member)
o For ‘N’ indicator:
When dbo. CMC_MEPE_PRCS_ELIG.CSCS_ID <> ‘MD11’
• Groups included:
o 100100 (Medicare)
o 100598 (Medicaid-OHP)
• Previous syntax
• select top 20000
• EXT_DATE,SUPPLIER_NAME,BUSINESS_UNIT,PROG_NO,PG_DESC,DIVISION_NO,RISKPOP_MEDICARE_EVENT_CODE,
• RISKPOP_MEDICAID_AID_CATEGORY,MEMBER_NO,MEDICARE_NO,MEDICAID_NO,LASTNAME,MIDINITIAL,FIRSTNAME,YMDBIRTH,
• a.SEX,CLASS,CL_DESC,S_LASTNAME,S_MIDINITIAL,S_FIRSTNAME,S_DOB,S_SEX,BENFIT_PKG,BEN_PKG_DESC,CLASS_ID,PLAN_ID,
• YMDEFF_BP,YMDEND,REASON,PRIME_SECOND,PHP_DUAL,S_ADDRESS1,S_ADDRESS2,S_ADDRESS3,S_CITY,S_STATE,S_ZIP,S_COUNTRY,
• S_PHONE,M_ADDRESS1,M_ADDRESS2,M_ADDRESS3,M_CITY,M_STATE,M_ZIP,M_COUNTRY,M_PHONE,DIV_NAME,PROV_NO,IRS_NO,
• P_LASTNAME,P_FIRSTNAME,P_MIDINITIAL,YMDEFF_PCP,ALT_KEY,ALT_CARRIER_NO,ALT_CARRIER_FUL,ALT_YMDEFF,ALT_YMDEND,
• BENFIT_PKG_EFF,BENFIT_PKG_TERM,a.MEME_CK,
• b.HIOS_NUMBER,
• null as PREMIUM_PAID_DATE,
• null as PREMIUM_PAID_END_DATE,
• b.APTC,
• null as 'GracePeriodIndicatorStartDate',
• null as'GracePeriodIndicatorEndDate',
• null as'ExchangePlanType'
• from Extract_602_603_PBH_Extract_Main a
• left join Extract_602_603_PBH_Extract_HRI b
• on LEFT(a.MEMBER_NO,7) = b.SBSB_ID
Syntax I am trying to implement(taking forever to execute) Please help correct
select distinct
EXT_DATE,SUPPLIER_NAME,BUSINESS_UNIT,PROG_NO,PG_DESC,DIVISION_NO,RISKPOP_MEDICARE_EVENT_CODE,
RISKPOP_MEDICAID_AID_CATEGORY,MEMBER_NO,MEDICARE_NO,MEDICAID_NO,LASTNAME,MIDINITIAL,FIRSTNAME,YMDBIRTH,
a.SEX,CLASS,CL_DESC,S_LASTNAME,S_MIDINITIAL,S_FIRSTNAME,S_DOB,S_SEX,BENFIT_PKG,BEN_PKG_DESC,CLASS_ID,PLAN_ID,
YMDEFF_BP,YMDEND,REASON,PRIME_SECOND,PHP_DUAL,S_ADDRESS1,S_ADDRESS2,S_ADDRESS3,S_CITY,S_STATE,S_ZIP,S_COUNTRY,
S_PHONE,M_ADDRESS1,M_ADDRESS2,M_ADDRESS3,M_CITY,M_STATE,M_ZIP,M_COUNTRY,M_PHONE,DIV_NAME,PROV_NO,IRS_NO,
P_LASTNAME,P_FIRSTNAME,P_MIDINITIAL,YMDEFF_PCP,ALT_KEY,ALT_CARRIER_NO,ALT_CARRIER_FUL,ALT_YMDEFF,ALT_YMDEND,
BENFIT_PKG_EFF,BENFIT_PKG_TERM,a.MEME_CK,
b.HIOS_NUMBER,
null as PREMIUM_PAID_DATE,
null as PREMIUM_PAID_END_DATE,
b.APTC,
null as 'GracePeriodIndicatorStartDate',
null as'GracePeriodIndicatorEndDate',
null as'ExchangePlanType',
case when MEPE.CSCS_ID = 'MD11' AND grgr.GRGR_ID IN('100100','100598')
THEN 'Y'
ELSE 'N' end as DualCoverageIndicator
from Extract_602_603_PBH_Extract_Main a
left join Extract_602_603_PBH_Extract_HRI b
on LEFT(a.MEMBER_NO,7) = b.SBSB_ID
join FacetsReport.dbo.CMC_MEPE_PRCS_ELIG MEPE
ON a.CLASS_ID= MEPE.CSCS_ID
Join FacetsReport.dbo.CMC_GRGR_GROUP grgr
ON MEPE.GRGR_CK= grgr.GRGR_CK
Randomize many int without same value - C#
Hi!
I have planned to make a C# Winform program where you randomize 27 values without same value. I have tested with a while loop but it doesn't work, some values is still similar to some other values. Here is my code:
private void button1_Click(object sender, EventArgs e)
{
Random rnd = new Random();
while (labelT27.Text == labelT1.Text && labelT27.Text == labelT2.Text && labelT27.Text == labelT3.Text &&
labelT27.Text == labelT4.Text && labelT27.Text == labelT5.Text && labelT27.Text == labelT6.Text &&
labelT27.Text == labelT7.Text && labelT27.Text == labelT8.Text && labelT27.Text == labelT9.Text &&
labelT27.Text == labelT10.Text && labelT27.Text == labelT11.Text && labelT27.Text == labelT12.Text &&
labelT27.Text == labelT13.Text && labelT27.Text == labelT14.Text && labelT27.Text == labelT15.Text &&
labelT27.Text == labelT16.Text && labelT27.Text == labelT17.Text && labelT27.Text == labelT18.Text &&
labelT27.Text == labelT19.Text && labelT27.Text == labelT20.Text && labelT27.Text == labelT21.Text &&
labelT27.Text == labelT22.Text && labelT27.Text == labelT23.Text && labelT27.Text == labelT24.Text &&
labelT27.Text == labelT25.Text && labelT27.Text == labelT26.Text && labelT26.Text == labelT1.Text &&
labelT26.Text == labelT2.Text && labelT26.Text == labelT3.Text && labelT26.Text == labelT4.Text &&
labelT26.Text == labelT5.Text && labelT26.Text == labelT6.Text && labelT26.Text == labelT7.Text &&
labelT26.Text == labelT8.Text && labelT26.Text == labelT9.Text && labelT26.Text == labelT10.Text &&
labelT26.Text == labelT11.Text && labelT26.Text == labelT12.Text && labelT26.Text == labelT13.Text &&
labelT26.Text == labelT14.Text && labelT26.Text == labelT15.Text && labelT26.Text == labelT16.Text &&
labelT26.Text == labelT17.Text && labelT26.Text == labelT18.Text && labelT26.Text == labelT19.Text &&
labelT26.Text == labelT20.Text && labelT26.Text == labelT21.Text && labelT26.Text == labelT22.Text &&
labelT26.Text == labelT23.Text && labelT26.Text == labelT24.Text && labelT26.Text == labelT25.Text &&
labelT25.Text == labelT1.Text && labelT25.Text == labelT2.Text && labelT25.Text == labelT3.Text &&
labelT25.Text == labelT4.Text && labelT25.Text == labelT5.Text && labelT25.Text == labelT6.Text &&
labelT25.Text == labelT7.Text && labelT25.Text == labelT8.Text && labelT25.Text == labelT9.Text &&
labelT25.Text == labelT10.Text && labelT25.Text == labelT11.Text && labelT25.Text == labelT12.Text &&
labelT25.Text == labelT13.Text && labelT25.Text == labelT14.Text && labelT25.Text == labelT15.Text &&
labelT25.Text == labelT16.Text && labelT25.Text == labelT17.Text && labelT25.Text == labelT18.Text &&
labelT25.Text == labelT19.Text && labelT25.Text == labelT20.Text && labelT25.Text == labelT21.Text &&
labelT25.Text == labelT22.Text && labelT25.Text == labelT23.Text && labelT25.Text == labelT24.Text &&
labelT24.Text == labelT1.Text && labelT24.Text == labelT2.Text && labelT24.Text == labelT3.Text &&
labelT24.Text == labelT4.Text && labelT24.Text == labelT5.Text && labelT24.Text == labelT6.Text &&
labelT24.Text == labelT7.Text && labelT24.Text == labelT8.Text && labelT24.Text == labelT9.Text &&
labelT24.Text == labelT10.Text && labelT24.Text == labelT11.Text && labelT24.Text == labelT12.Text &&
labelT24.Text == labelT13.Text && labelT24.Text == labelT14.Text && labelT24.Text == labelT15.Text &&
labelT24.Text == labelT16.Text && labelT24.Text == labelT17.Text && labelT24.Text == labelT18.Text &&
labelT24.Text == labelT19.Text && labelT24.Text == labelT20.Text && labelT24.Text == labelT21.Text &&
labelT24.Text == labelT22.Text && labelT24.Text == labelT23.Text && labelT23.Text == labelT1.Text &&
labelT23.Text == labelT2.Text && labelT23.Text == labelT3.Text && labelT23.Text == labelT4.Text &&
labelT23.Text == labelT5.Text && labelT23.Text == labelT6.Text && labelT23.Text == labelT7.Text &&
labelT23.Text == labelT8.Text && labelT23.Text == labelT9.Text && labelT23.Text == labelT10.Text &&
labelT23.Text == labelT11.Text && labelT23.Text == labelT12.Text && labelT23.Text == labelT13.Text &&
labelT23.Text == labelT14.Text && labelT23.Text == labelT15.Text && labelT23.Text == labelT16.Text &&
labelT23.Text == labelT17.Text && labelT23.Text == labelT18.Text && labelT23.Text == labelT19.Text &&
labelT23.Text == labelT20.Text && labelT23.Text == labelT21.Text && labelT23.Text == labelT22.Text &&
labelT22.Text == labelT1.Text && labelT22.Text == labelT2.Text && labelT22.Text == labelT3.Text &&
labelT22.Text == labelT4.Text && labelT22.Text == labelT5.Text && labelT22.Text == labelT6.Text &&
labelT22.Text == labelT7.Text && labelT22.Text == labelT8.Text && labelT22.Text == labelT9.Text &&
labelT22.Text == labelT10.Text && labelT22.Text == labelT11.Text && labelT22.Text == labelT12.Text &&
labelT22.Text == labelT13.Text && labelT22.Text == labelT14.Text && labelT22.Text == labelT15.Text &&
//And so on
//Later, inside the while loop
{
i = rnd.Next(1, 100);
labelT1.Text = rnd.Next(1, 28).ToString();
labelT2.Text = rnd.Next(1, 28).ToString();
labelT3.Text = rnd.Next(1, 28).ToString();
labelT4.Text = rnd.Next(1, 28).ToString();
labelT5.Text = rnd.Next(1, 28).ToString();
labelT6.Text = rnd.Next(1, 28).ToString();
labelT7.Text = rnd.Next(1, 28).ToString();
labelT8.Text = rnd.Next(1, 28).ToString();
labelT9.Text = rnd.Next(1, 28).ToString();
labelT10.Text = rnd.Next(1, 28).ToString();
labelT11.Text = rnd.Next(1, 28).ToString();
labelT12.Text = rnd.Next(1, 28).ToString();
labelT13.Text = rnd.Next(1, 28).ToString();
labelT14.Text = rnd.Next(1, 28).ToString();
labelT15.Text = rnd.Next(1, 28).ToString();
labelT16.Text = rnd.Next(1, 28).ToString();
labelT17.Text = rnd.Next(1, 28).ToString();
labelT18.Text = rnd.Next(1, 28).ToString();
labelT19.Text = rnd.Next(1, 28).ToString();
labelT20.Text = rnd.Next(1, 28).ToString();
labelT21.Text = rnd.Next(1, 28).ToString();
labelT22.Text = rnd.Next(1, 28).ToString();
labelT23.Text = rnd.Next(1, 28).ToString();
labelT24.Text = rnd.Next(1, 28).ToString();
labelT25.Text = rnd.Next(1, 28).ToString();
labelT26.Text = rnd.Next(1, 28).ToString();
labelT27.Text = rnd.Next(1, 28).ToString();
}
}
P. S. I'm a beginner in C#
Date Comparison In Entity Framework Linq Query
Declare a DateTime variable before and compare to this one:
DateTime dt = DateTime.Now.Date;
var bookings = context.Bookings.Include("BookingItems").Where(x=>x.IsDeleted == false && DbFunctions.TruncateTime(x.BookingDate).Value == dt).ToList();
Please remember to mark helpful posts as answer and/or helpful.
Stored procedure: how to update multiple tables, how to avoid database lock, how to return multline table
I prefer to use different stored procedures to do different things.
CREATE PROCEDURE [dbo].usp_updatedata
(@id CHAR(12)
,@Date DATETIME
)
AS
BEGIN
Update Table_mocha
SET P4=LTRIM(RTRIM(Nullif(Replace(PE4,RTRIM(Cast(Q_ID as varchar(10))), ''),'')))
where id=@id and order_dt=@Date
End
CREATE PROCEDURE [dbo].usp_getData
(@id CHAR(12)
,@Date DATETIME
)
AS
BEGIN
SET NOCOUNT ON;
SELECT id, ln_id,p4, P9,P11
where id=@id and order_dt=@Date
End
Stored procedure: how to update multiple tables, how to avoid database lock, how to return multline table
is it possible to combine your two SP in one SP or is it the best practice to separate SPs based on their rolls
I also notice in the 2nd SP dont output or return the results from Select statment? is your 2nd SP
[dbo].usp_getData
return table
Stored procedure: how to update multiple tables, how to avoid database lock, how to return multline table
Stored procedure: how to update multiple tables, how to avoid database lock, how to return multline table
do you think from best practice is okay to do the following
1. create SP to update
2. Show result using SP
3. Create SP to include #1 and #2
do you think SP can recalled in MS access 2010?
How to update different custom list items in sharepoint 2010 using EventReciver class
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
if (properties.ListTitle == "EmpDetails")
{
//save before value of changed item
string beforeTitle = properties.BeforeProperties["Title"].ToString();
SPList listEmpHistory =properties.Web.Lists["EmpHistory"];
SPListItemCollection macthedItems = listEmpHistory.GetItems(GetItemsByTitleQuery(beforeTitle));
if(matchedItems.Count > 0)
{
foreach(var item in matchedItems)
{
//change title to new source item title
item["Title"] = properties.AfterProperties["Title"].ToString();
item.Update();
}
}
}
}
//query to get all items where title equal source title
public SPQuery GetItemsByTitleQuery(string itemTitle)
{
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>"+itemTitle+"</Value></Eq></Where>";
return query;
}
If i get u right, u can use something like that
Locating Outlook dll
I have my C#, Asp.net website which Opens my outlook mail item on clicking a button. I have added Microsoft.office.interop.outlook.dll version 12.0 to my bin from .NET.
While running the application, from which location it will take my dll. Either from bin or from GAC?
Because I have installed Outlook in my local machine. so I can able to run my code. But once I publish the code to Server, I could not able to run my application. It is throwing me an error '
Could not load file or assembly 'Microsoft.Office.Interop.Outlook, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
' I dont have outlook dll in my server.
Please suggest
How to access sharepoint 2010 data into normal desktop based asp.net application
Sharepoint 2010 is already developed on another server ,
I am developing asp.net appliction on localhost ,
on my system i have installed vs 2010 express,
i want to access data without installing sharepoint 2010 on my system
plz give me step by step solution with code
How to access sharepoint 2010 data into normal desktop based asp.net application
Hi,
SharePoint 2010 provides REST based WCF Data Services to expose SharePoint data to third party applications.
Please take a look at the following links.
Accessing SharePoint 2010 Lists by Using WCF Data Services
Access sharepoint list from web site hosted externally from sharepoint
Microsoft MVP - ASP/ASP.NET
Passing the value in action property of a text box
Hi
I have question I want to move to another report if the user is clicking on a value. So I have pass a value of the same row.
Example
If I click on 5 I will go to the next report so I need to pass the load ID value as a parameter to the next report.
Please suggest me how to do this.
Thanks, Subrat Kumar
Passing the value in action property of a text box
Simply use Navigation properties of textbox which shows Error Count and inside it use the Jump to Report (if other report is also in the same project) or jump to URL option.
If using jump to report it will give you option to map parameters. map the LoadID parameter with below expression
=Fields!LoadID.Value
assuming LoadID is name of field in your dataset which shows value as 793749 above
if using jump to URL you need to append this to report url as
="<report url path here>?<report folder path>¶metername=" & CStr(Fields!LoadID.Value)
also see
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
----------------------------
My MSDN Page
My Personal Blog
My Facebook Page
Passing the value in action property of a text box
Hi Visakh,
I have tried the process but I am getting the following error
an error occurred during local report processing. an attempt was made to set a report parameter that is not defined,
please suggest me the fix.
Thanks, Subrat Kumar
How to crteate time series report which shows the Schedule Variance/Schedule Performance
Hi All,
I have to create 2 SSRS time series reports to show the schedule variance/ schedule performance.
Please help me to create these reports. Is there any formula to find schedule variance/ schedule performance.? How do I calculate that?
Regards,
Julie
Thursday, October 30, 2014
BIDS Deployment issue in SharePoint integrated mode
Still haven't had any luck with this and would love to find resolution ASAP.
Any suggestions would be most welcome!
Thanks
-- Adam
Validations in visual webparts
Hi All,
I implemented a visual webpart.That webpart is having different controls text box and dropdown,radio button,check box.I needs to implement validations for each control using client script.Please share the code sample to implement validations.Please help.thanks in advance.
Regards,
Praveen
Problem Retrieving SPFileVersion
I'm making a .txt to store each version of a file after I perform a certain action.
The code I'm running is simple:
write("version number: 0.1");
write("modified : " + file.Item["Created"].ToString());
write("modified by: " + file.Author.Name);
write("Check in comment : " + file.CheckInComment);
foreach( SPFileVersion version in file.Versions){
if (version.VersionLabel != "0.1"){
write("version number: "+ version.VersionLabel);
write("modified : " + version.Created.ToLocalTime());
write("modified by: " + version.CreatedBy.Name);
write("Check in comment : " + version.CheckInComment);
}
}
The code does not go inside the foreach. If the code I wrote is correct, that means my files does not have any versions stored? If so, how do I do this?
I added a new .docx on a library, did check-out and check-in. Edited the file with another user, and then again a check-out and check-in. But I can't seem to get in the foreach.
Thanks!
Deleted Doc Libraries Will Not Go Away...
Michael P. O'Hara
How to replace certain letters in a string
How to replace certain letters in a string
Try this:
Dim pass As String = "Chipotle"
Dim pass2 As String = pass.Replace("o", "0").Replace("t", "7").Replace("l", "1").Replace("e", "3")
MessageBox.Show(pass2)
Note that the Replace method is case sensitive. If you want both upper case "O" and lower case "o" to be changed to number "0", you will need two calls to Replace: Replace("O", "0").Replace("o", "0")
Connect with access
Dim Table_ As String = "Table1"
Dim query As String = "SELECT * FROM " & Table_
Dim MDBConnString_ As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=TestDatabase.mdb;"
Dim ds As New DataSet
Dim cnn As OleDbConnection = New OleDbConnection(MDBConnString_)
cnn.Open()
Dim cmd As New OleDbCommand(query, cnn)
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, Table_)
cnn.Close()
Dim t1 As DataTable = ds.Tables(Table_)
DataGridView1.DataSource = t1
SqlBulkCopy Converting string to datetime with US Format
I'm transferring date from an unknown source (Could be csv/SQL Server) to an application database, As i don't know where the data is coming from I first import the data into a holding table (all Varchar Columns) I then test is the value in the column matches what it should be and import to the database or flag a data error
To transfer the data i load the data into a DataTable in C# then use the SqlBulkCopy to insert the data to the holding table.This is all working but i'm getting an issue with datetime columns. In the C# DataTable the date value is in YMD format and is stored as a string, the column in the holing table is a varchar(255) but at some point the transfer process the date is being converted to DMY format this is then causing an issue when I try to validate the dates in the holding table.
To Load the DataTable I do:
cmd.CommandText = string.Format("SET DATEFORMAT YMD; {0}", cmd.CommandText);
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
DataTable returnTable = new DataTable();
dataAdapter.Fill(returnTable);
To Transfer the data I do:
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(DBContext.ConnectionString, SqlBulkCopyOptions.KeepNulls))
{
bulkCopy.DestinationTableName = "HoldingTable";
bulkCopy.BatchSize = 10000;
foreach (impMap im in ImportMapping.Where(i => i.IsImported))
{
bulkCopy.ColumnMappings.Add(im.MappingColumn, im.TableField.FieldName);
}
foreach (SqlBulkCopyColumnMapping m in columnMappings)
{
bulkCopy.ColumnMappings.Add(m);
}
bulkCopy.WriteToServer(dataDataTable);
}
inserting values from a table to another
Hello,
There is a known issue reported with SQL 2008 and SQL 2008 R2 :
Please check if we are not hitting this known issue:
FIX: Query failure and an "Invalid column name" error message occur when you run a linked server query to another instance of SQL Server 2008 or SQL Server 2008 R2
Fix:
Cumulative update package 10 for SQL Server 2008 Service Pack 1
Cumulative update 1 for SQL Server 2008 Service Pack 2
Cumulative Update package 5 for SQL Server 2008 R2
Regards, Don Rohan [MSFT]
inserting values from a table to another
Hello,
There is a known issue reported with SQL 2008 and SQL 2008 R2 :
Please check if we are not hitting this known issue:
FIX: Query failure and an "Invalid column name" error message occur when you run a linked server query to another instance of SQL Server 2008 or SQL Server 2008 R2
Fix:
Cumulative update package 10 for SQL Server 2008 Service Pack 1
Cumulative update 1 for SQL Server 2008 Service Pack 2
Cumulative Update package 5 for SQL Server 2008 R2
Regards, Don Rohan [MSFT]
I am using sql 2012
inserting values from a table to another
Try below
INSERT INTO PresentTotalTime (preTotalTimeUsed)
SELECT
Ttup
FROM lasr
INNER JOIN PresentTotalTime
ON PresentTotalTime.EmailAddress = lasr.EmailAddress
-Vaibhav Chaudhari
inserting values from a table to another
Try below
Update PresentTotalTime
SET preTotalTimeUsed = Ttup
FROM lasr
WHERE PresentTotalTime.EmailAddress = lasr.EmailAddress
-Vaibhav Chaudhari
inserting values from a table to another
Try below
Update PresentTotalTime
SET preTotalTimeUsed = Ttup
FROM lasr
WHERE PresentTotalTime.EmailAddress = lasr.EmailAddress-Vaibhav Chaudhari
update actually works, thanks
Speed it takes to write to disk
Alan
Speed it takes to write to disk
I would suggest using SQLIO (which has nothing to do with SQL Server) to test the raw disk speed.
Please see:
Speed it takes to write to disk
I'm not sure what scenario are you trying to test?
But I think the SQLIOSim utility from Microsoft may help. This can be freely downloadable from here.
Also have a read the following articles.
The SQL Server Sqliosim Utility
Stress testing using SQLIOSIM and SQLIO - Video
Krishnakumar S
Speed it takes to write to disk
Hello Alan,
As Tom mentioned: SQLIOSim tool can be used to simulate the SQL activity.
SQLIO Disk Subsystem Benchmark Tool
How to use the SQLIOSim utility to simulate SQL Server activity on a disk subsystem
http://ift.tt/13jI09GThis is a good article too:
Regards, Don Rohan [MSFT]
Speed it takes to write to disk
Hello Alan,
SQL Server don't write new data directly to disk, it's done by the "Lazy Background Writer" process.
See Storage I/O Performance Tester, a PowerShell script which utilize SqlIo, the tool mentioned by Tom.
Olaf Helper
[ Blog] [ Xing] [ MVP]
Speed it takes to write to disk
I want T-SQL. I do not want to use ANYTHING else. I want a script I can run. Could probably be done with stats or writing to a text file or something.
Alan
Speed it takes to write to disk
Alan
Speed it takes to write to disk
Best Regards,Uri Dimant SQL Server MVP, http://ift.tt/1iQ9JkR
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting: Large scale of database and data cleansing
Remote DBA Services: Improves MS SQL Database Performance
SQL Server Integration Services: Business Intelligence
When clicking on the Close Button force the app to NotRunning state?
Hi,
When clicking on the Close Button force the app to NotRunning state? The problem is the I have multi-view, when click on the close button then the second view is closed but the first view goes to suspending mode/state. That produce un-expect result.
Thanks and Best Regards,
Weera
Is there any way to access database in BackgroundTask
Is there any way to access database in BackgroundTask
Charting in Visual Studio 2013
Hi Q,
You may didn't drag and drop to the right page. In Default.aspx can do it. Please try again.
According to your description, you are doing Asp.Net application. So please post in related to ASP.NET forum. This forum is discuss C# development issue. Thanks for your understanding.
Have a nice day!
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Returning results based on Month entry
I need to write a script that will allow the user to enter a month value, for example 'October' and it should return two values.
The 1st Monday of the month, which i think i have worked out, please see below script (please correct me if im wrong)
SELECT DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(DAY, 6 - DATEPART(DAY, GETDATE()), GETDATE())), 0)
and the last sunday of the same month, but because i need full weeks results meaning from Monday to Sunday, i want it to return Sunday 2nd November.
Is this possible?
Skip minutes from date and time field
Chek This out,
Declare
@Data Datetime = '2014-10-16 12:10:00.000'
Select
@Data , Convert ( Varchar ( 16 ), @Data , 120 )
Please have look on the comment
Skip minutes from date and time field
Is that what you are looking for?
DECLARE @Dt AS DATETIME;
SET @Dt = '2014-10-16 12:10:00.000'
SELECT CONVERT(VARCHAR(16), @Dt, 120);
If this is only for display purpose the application code can handle this. If your using this in a SQL query for filtering then native datetime data type is recommended for performance.
You can read more on below articles:
What is the most efficient way to trim time from datetime? - Aaron Bertrand
Bad habits to kick : mis-handling date / range queries - Aaron Bertrand
Krishnakumar S
Skip minutes from date and time field
make it smalldatetime if you dont want beyond minute precision
Declare
@Data Datetime='2014-10-16 12:10:45.000'
Declare
@Datasdt smalldatetime='2014-10-16 12:10:45.000'
Select
@Data,Convert(smalldatetime,@Data) as converted,@Datasdt as direct
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
----------------------------
My MSDN Page
My Personal Blog
My Facebook Page
Daily sync of medium amount of data. How to realize with Windows Store App?
Hi Martin,
Based on my knowledge, you are using the correct way for synchronized data. TimerTrigger class can help us to execute a task at a particular time. BackgroundDownloader class is primarily designed for long-term transfer operations for resources. So there is no time restriction limit with BackgroundDownloader class.
If you still have questions, please post more information about your scenario.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
Can i blur the background when the popup is opened in windows store app
Customize the report margin while rendering
I found the solution. Device info have has the value without metric. The below device info is correct one. Thanks to all ;)
<DeviceInfo><PageWidth>11in</PageWidth><PageHeight>8.5in</PageHeight><MarginTop>.25in</MarginTop><MarginBottom>.25in</MarginBottom><MarginLeft>.25in</MarginLeft><MarginRight>.25in</MarginRight></DeviceInfo>
Developer
Skip minutes from date and time field
Hi,
i have a date time column in my table. for example the value is '2014-10-16 12:10:00.000'
i need to select only the value '2014-10-16 12:10'. means without minutes.
how to achieve this?
Thanks
Kasim
"Failed to use non CLS compliant type" when iterating SPLimitedWebPartManager.WebParts
I haven't been able to get passed this while using the web part manager, so instead I used the SharePoint web part pages web service, using this article from Raymond Mitchell as a reference:
Update a SharePoint 2010 Web Part from PowerShell
The web service returns all the web parts as an XML string, which can be converted to an XML Document, and I was then able to update the nodes I needed.
The workflow could not update the item, possibly because one or more columns for the item require a different type of information
Hello Steven,
There is default Document Type content type . Its an OOTB Approval workflow template.
Yes one more information I can give you is when we Uncheck "Start this workflow to approve publishing a major version of an item" the workflow works fine without any issue.
Let me know if you need any more details.
Regards,
Purvish Shah
The workflow could not update the item, possibly because one or more columns for the item require a different type of information
Hi Purvish,
This issue may be due to the Approval workflow is corrupted.
I recommend to re-publish the OOB Approval workflow to SharePoint with the following steps:
- Deactivate workflow feature from site collection.
- Use SharePoint Designer and delete the OOB Approval workflow from the site collection.
- Reactivate feature and verify Approval workflow is recreated.
Best regards,
Thanks
Victoria Xia
TechNet Community Support
SharePoint 2010 How much space does a user actually have?
If for example I create a site collection and give it a quota of 10gb, I'm wondering how much actual space is available for storage? I've been doing some research into this and have read about the files being stored in the DB as BLOBs and so explaining that there is overhead when files are stored in a SQL DB but it didn't explain what the overhead is.
Any further info on this would be brilliant.
SharePoint 2010 How much space does a user actually have?
Hi Fbyrne,
Per my knowledge, there is overhead in SharePoint content database, such as metadata for the files uploaded to SharePoint.
And the size of the overhead in your database is depends on the content in your site.
If a user upload a document to SharePoint, SQL needs to keep auxiliary structures such as transactions logs, indexes, document properties in order to store the document.
So if the overhead is too big, you can clean up the space by the SQL database defragmentation and shrink operations.
More references:
Best regards.
Thanks
Victoria Xia
TechNet Community Support
Wednesday, October 29, 2014
Crystal Reports
How to combine below 4 queries into a single query?
Its evident that you're on Oracle
Please post in some Oracle forums
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
----------------------------
My MSDN Page
My Personal Blog
My Facebook Page
Is there any way to access database in BackgroundTask
Is there any way to access database in BackgroundTask
The Remote server returned an error (404) not found in SharePoint Client Context code
Hi All,
I am getting an error with below line.
"The Remote server returned an error (404) not found"
It occurs when I am trying to fetch some data from SharePoint 2010 List.
For eg. I have a webpart in which i am showing some content on page load and that content is coming from a List.
But I am getting error.
Screen shot for your reference.
The Remote server returned an error (404) not found in SharePoint Client Context code
Hello,
It seems there is problem with permission that's why 404 is returning. Have you tried to add credential in your code? If not then do so
using (var context = new ClientContext("site URL"))
{
context.Credentials = new NetworkCredential("userName", "Userpassword", "domain");
var site = context.Web;
context.Load(site, s => s.Title);
context.ExecuteQuery();
Console.WriteLine(site.Title);
Console.ReadLine();
}
If still face issue then share your code with us.
Hemendra:Yesterday is just a memory,Tomorrow we may never see<br/> Please remember to mark the replies as answers if they help and unmark them if they provide no help
SSRS_LoadReportError
Andy Tauber
Data Architect
The Vancouver Clinic
Website | LinkedIn
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
hi friends,
Attempted to read or write protected memory. This is often an indication that other memory is corrupt. how to solve it.
Invalid operation exception while executing Type.GetType
I would check precisely what you have in
gatewayPluginConfiguration.Type
It should be a string and it should exactly match a type in the executing assembly.
Not forgetting name space.
I guess it doesn't.
Invalid operation exception while executing Type.GetType
Invalid operation exception while executing Type.GetType
Caillen,
Thank you for your reply, what you're showing me is exactly what i'm seeing in my application. And your answer makes some things clear. But has this any connection with the fact that i'm receiving an empty object when i call:
Activator.CreateInstance(gatewayPluginType)
or is that a totally different issue?
Invalid operation exception while executing Type.GetType
Yes that's a different issue.
There may be many reasons for this problem. Firstly you could make sure gatewayPluginType is a valid type, the type name should consists of a valid namespace and a type name. Don't cast it to a incompatible type with "as" keyword, or you'll get null value.
If gatewayPluginType is not null, but the return value of Activator.CreateInstance is still null, it'll be a very strange problem, you need to make a sample project, post the whole code here or upload the project file in OneDrive so that we can debug it and find out what's going on.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Invalid operation exception while executing Type.GetType
Thanks for your,
I found out that the NullReferenceException was actually a missing method exception which occured. And that error occured because i made a mistake in the methods for loading the configuration file. But by now i fixed the problem and everything is working fine. Thank you all for your answers!
Reverse engineer a DLL using .net Reflector
You have to import(Add) that dll into .Net Reflector tool.there is option for it.
after that that list of namespaces are displayed below on right corner inside that code for each class is present.
but the extracted code is not always same as original code. in some cases .Net Reflector tool adds something to complete that code. dotPeek is free tool for it.
Tuesday, October 28, 2014
making an int field in a table null
hi guys!
i have a windows form named form1 and a tblEmp with the following fields;
id int, Fname text, Lname text, Dob datetimepicker and age int
i also have on form1 two buttons Save and Retrieve and a textbox for searching by id #
the save button works fine, if i save a record with no age it saves and that's fine
but when i click the retrieve button;
the information come up which is great but age come up as 0;
in the table i made the age field (allow null)
can someone help me?
i tried age.text = "";
and it's still saving a 0 in the age field in the table.
i want the field to be blank when i click the retrieve button.
making an int field in a table null
Difference between .NET framework versions and ASP.NET versions
Geeting TIMEOUT while executing a Stored Procedure.
Hey Satish,
If you have used any transaction make sure it is either committed or rolled back in any other session.
Check if thr are any while loop and it is entering into Infinite Loop.
Thanks,
Please have look on the comment
Geeting TIMEOUT while executing a Stored Procedure.
If you are executing a stored procedure within SSMS it uses the command timeout of SSMS from Tools -> Options -> Query Execution -> Execution time-out.
If you are using code to execute it you need to set the .Timeout property (e.g. of SQLCommand) either to zero or something "large".
Generally setting timeout to zero is not a good idea. Something will break, or lock or even worse... dead-lock sooner or later.
See if you're recursively calling the stored procedure by mistake. Infinite loops should also be in your checklist. Common things to check are indexes, forgotten where clauses, cartesian products, locks.
To get more help you should post your stored procedure and objects it references plus at least some estimate of a row count.
"If there's nothing wrong with me, maybe there's something wrong with the universe!"
Select top 1 record from a table which has duplicates - Please help!
;With cte As
(Select ID, DeptId, Marks,
Row_Number() Over(Partition By ID Order By Marks Desc) As rn
From #Student)
Select ID, DeptId, Marks
From cte
Where rn = 1
Order By ID;
Tom
Select top 1 record from a table which has duplicates - Please help!
Select Id,DeptiD,Marks From (
Select Row_Number() Over (Partition By Id Order By Marks Desc) As RwNum,* FROm #Student
)Data
Where RwNum = 1
Check this
Please have look on the comment
How to turn on/off the flashlight in Win8.1 tablet
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="TorchButton" Content="Turn Torch On" Click="TorchButton_Click"/>
</Grid>
MediaCapture MyMediaCapture = new MediaCapture();
private async void TorchButton_Click(object sender, RoutedEventArgs e)
{
await MyMediaCapture.InitializeAsync();
var MyVideoDeviceController = MyMediaCapture.VideoDeviceController;
var MyTorch = MyVideoDeviceController.TorchControl;
if (MyTorch.Supported)
{
if ((TorchButton.Content as string) == "Turn Torch On")
{
TorchButton.Content = "Turn Torch Off";
MyTorch.PowerPercent = 100;
MyTorch.Enabled = true;
}
else
{
TorchButton.Content = "Turn Torch On";
MyTorch.PowerPercent = 0;
MyTorch.Enabled = false;
}
}
else
{
TorchButton.Content = "Torch not supported!";
}
}
}
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.
How to display the actual reading alone the dot and conditional change the color of the dot/figure if it is over / below an alert figure
Hi,
Please help on how to achive the subjected... Thanks
How to display the actual reading alone the dot and conditional change the color of the dot/figure if it is over / below an alert figure
Hi,
You have to explain your problem clearly with as much details as possible including the version of the SQL you are using so that everyone here can understand. From the title of your post it looks like that you want to change the color of the data series marker (the dot in the picture above) in a SSRS chart.
If I have understood you correctly then here is how you can do it.
1. Select the data series properties. Select and right click on the line in the chart in design mode. Then click on "Series Properties" and go to the properties tab for "Markers". Under "Marker Color" drop down select the expression and set the expression as shown in the picture. Replace "Field!Qty.Value" with appropriate field and the criteria for the upper and lower bound you want with their respective color.
2. You can see in the snapshot below that the color of January Month has changed to Red since the qty value is less than 300 as set in the expression above.
--sIbu
How to display the actual reading alone the dot and conditional change the color of the dot/figure if it is over / below an alert figure
Hi,
I am using SQL2012 R2 EXPRESS
Please also advise how to add the figures on every dot as attached
Retrieve users who are not added to any group in site permissions page
Hi,
You can use the SPWeb.Users property which “Gets the collection of user objects that are explicitly assigned permissions in the website”.
Thanks
Patrick Liang
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com
Patrick Liang
TechNet Community Support
Retrieve users who are not added to any group in site permissions page
Hi,
I am looking for the users in "user.aspx" page alone. I have 10 users who are not part of any group and added in site permissions page. There are some other users who have been assigned list level permission. But I am looking for the users in "user.aspx" alone.
Thanks
How Can i read Domain group from sharepoint site permission
How Can i read Domain group from sharepoint site permission
Try below tools
http://ift.tt/NRFJ8b
http://ift.tt/1oZe4cY
If this helped you resolve your issue, please mark it Answered
How Can i read Domain group from sharepoint site permission
Hi Sanjay,
Please go through below link for more details on this.
http://ift.tt/1tgBSaD
Regards
Soni K
Central Administration > Manage Reporting Services Application - SSRS Service Application PSQA > System Settings
Just to confirm, You have installed SSRS on SharePoint WFE?
If yes, then download and install Reporting server addin for SharePoint.
Track Office file changes
How to scroll a ListView programmatically
I have created a ListView with footer in my window phone application. How can I programmatically scroll the ListView so that the footer is visible?
Thank you.
SharePoint 2010 calendar overlay
Hello Alex,
Just to confirm you are performing Calendar overlay on site collection and not in between 2 web application.
If yes, then deleting the Overlay and configuring it back should resolve the issue.
Thank You, Pallav S. Srivastav If this helped you resolve your issue, please mark it Answered
Challenge with Pivoting data
Hi Everyone,
I have an interesting challenge which involves extracting data from two related databases, and pivoting part of the data from the second.
Where I work we use SAP Business One (ERP) in concert with Accellos (WMS). Within our Warehouses we store items in many bin locations. Bin locations; items in those locations, along with quantities, etc are stored in the Accellos database. Master data related to the items themselves, such as the item cost, preferred supplier, etc is stored in SAP Business One.
Whilst I have been able to create reports which successfully bridge both SAP & Accellos, such as that shown below, I have not been able to present the data output in an ideal format.
As can be seen above given a single item code (e.g.: DR1124) there are many bin labels (and corresponding quantities) returned.
I would like to show the bin labels 'horizontally' in the fashion illustrated below -
I believe that using a Pivot is pivotal (excuse the pun!) to success in my endeavour, and due to this I have studied up on Pivots, both the Static type (which I am now comfortable with) and the Dynamic type (which I am still getting 'my head around').
However there are a couple of challenges related to my specific pivot.
- The maximum number of Bins (and correspondingly Bin Labels) per Item change
- There are over 10K Bin Labels
I have written a basic Dynamic Pivot which shows all Bin Labels horizontally, like so...
DECLARE @SQL nvarchar(max), @Columns nvarchar(max)
SELECT @Columns =
COALESCE(@Columns + ', ', '') + QUOTENAME(BINLABEL)
FROM
(
SELECT DISTINCT
BINLABEL
FROM A1Warehouse..BINLOCAT
) AS B
ORDER BY B.BINLABEL
SET @SQL = '
WITH PivotData AS
(
SELECT
BINLABEL
, PRODUCT
, QUANTITY
FROM A1Warehouse..BINLOCAT
)
SELECT
PRODUCT,
'+ @Columns +'
FROM PivotData
PIVOT
(
SUM(QUANTITY)
FOR BINLABEL
IN('+ @Columns +')
) AS PivotResult'
EXEC(@SQL)
The above technique gives me over 10K columns because there are that many Bin Labels in total.
It occurred to me that I would need to count the maximum number of Bin Labels for the Item that had the most Bin Labels, and that this number would then need to be used to set the maximum number of columns.
DECLARE @maxBins int
DECLARE @loopCount int = 1
SET @maxBins = (SELECT MAX([# of Bins]) AS 'Max Bins'
FROM
(
SELECT
COUNT(BINLABEL) '# of Bins'
FROM A1Warehouse..BINLOCAT
GROUP BY PRODUCT
) AS T0)
PRINT @maxBins
At this point in time one item occupies a total of 26 bin labels / locations. Every other item occupies less than 26 bin labels / locations, so I now know that I need to number my vertical columns as 'Bin 1', 'Bin 2', 'Bin 3', 'Bin...', 'Bin 26'.
This is where the fun starts, I don't exactly need a Dynamic Pivot, but neither is a Static Pivot up to the task (at least not as best I can tell).
Here is the Static Pivot query that I have written -
DECLARE @fromDate DATE = DATEADD(YY, -1, GETDATE())
DECLARE @toDate DATE = GETDATE()
DECLARE @maxBins int
DECLARE @loopCount int = 1
SET @maxBins = (SELECT MAX([# of Bins]) AS 'Max Bins'
FROM
(
SELECT
COUNT(BINLABEL) '# of Bins'
FROM A1Warehouse..BINLOCAT
GROUP BY PRODUCT
) AS T0)
PRINT @maxBins
SELECT *
FROM
(
SELECT
Tx.[Item Code]
, Tx.Description
, SUM(Tx.[Sales (last 12 Months)]) AS 'Sales (last 12 Months)'
, ISNULL(Tx.[Supplier Code], '') AS 'Supplier Code'
, ISNULL(Tx.[Supplier Name], '') AS 'Supplier Name'
, Tx.OnOrder
, Tx.IsCommited
, Tx.OnHand
, ISNULL(Tx.BINLABEL, '') AS 'Binlabel'
, ISNULL(CAST(Tx.QUANTITY AS nvarchar), '') AS 'Quantity'
FROM
(
SELECT
T0.ItemCode AS 'Item Code'
, T0.Dscription AS 'Description'
, SUM(T0.Quantity) AS 'Sales (last 12 Months)'
, T3.CardCode AS 'Supplier Code'
, T3.CardName AS 'Supplier Name'
, T2.OnOrder
, T2.IsCommited
, T2.OnHand
, T4.BINLABEL
, T4.QUANTITY
FROM INV1 T0
INNER JOIN OINV T1 ON T1.DocEntry = T0.DocEntry AND T1.CANCELED = 'N'
INNER JOIN OITM T2 ON T2.ItemCode = T0.ItemCode
LEFT JOIN OCRD T3 ON T3.CardCode = T2.CardCode
LEFT JOIN A1Warehouse..BINLOCAT T4 ON T4.PRODUCT = T0.ItemCode collate SQL_Latin1_General_CP850_CI_AS
WHERE T1.DocDate >= @fromDate AND T1.DocDate <= @toDate
GROUP BY T0.ItemCode, T0.Dscription, T3.CardCode, T3.CardName, T2.OnOrder, T2.IsCommited, T2.OnHand, T4.BINLABEL, T4.QUANTITY
UNION ALL
SELECT
T0.ItemCode AS 'Item Code'
, T0.Dscription AS 'Description'
, -SUM(T0.Quantity) AS 'Sales (last 12 Months)'
, T3.CardCode AS 'Supplier Code'
, T3.CardName AS 'Supplier Name'
, T2.OnOrder
, T2.IsCommited
, T2.OnHand
, T4.BINLABEL
, T4.QUANTITY
FROM RIN1 T0
INNER JOIN ORIN T1 ON T1.DocEntry = T0.DocEntry
INNER JOIN OITM T2 ON T2.ItemCode = T0.ItemCode
LEFT JOIN OCRD T3 ON T3.CardCode = T2.CardCode
LEFT JOIN A1Warehouse..BINLOCAT T4 ON T4.PRODUCT = T0.ItemCode collate SQL_Latin1_General_CP850_CI_AS
WHERE T1.DocDate >= @fromDate AND T1.DocDate <= @toDate
GROUP BY T0.ItemCode, T0.Dscription, T3.CardCode, T3.CardName, T2.OnOrder, T2.IsCommited, T2.OnHand, T4.BINLABEL, T4.QUANTITY
)Tx
GROUP BY Tx.[Item Code], Tx.Description, Tx.[Supplier Code], Tx.[Supplier Code], Tx.[Supplier Name], Tx.OnOrder, Tx.IsCommited, Tx.OnHand, Tx.BINLABEL, Tx.QUANTITY
)Ty
PIVOT
(
MAX(Ty.Quantity)
FOR Ty.Binlabel IN ([0], [1], [2])
)Tz
Here is a screen shot of the results that I see -
I understand why there are NULLs in my 0, 1, and 2 columns...there simply aren't Bin Labels called 0, 1 or 2!
My challenge is that I do not know how to proceed from here. Firstly how do I call each of the pivoted columns 'Bin 1', 'Bin 2', 'Bin...', 'Bin 26' when the actual Bin Labels are over 10 thousand different possible character sets, e.g.: #0005540, K1C0102, etc, etc, etc...
I have considered the possibility that a WHILE loop may be able to serve in populating the column names...
DECLARE @maxBins int
DECLARE @loopCount int = 1
SET @maxBins = (SELECT MAX([# of Bins]) AS 'Max Bins'
FROM
(
SELECT
COUNT(BINLABEL) '# of Bins'
FROM A1Warehouse..BINLOCAT
GROUP BY PRODUCT
) AS T0)
PRINT @maxBins
WHILE @loopCount <= @maxBins
BEGIN
PRINT @loopCount
SET @loopCount = @loopCount +1
END
...of course the query above has no practical application at this stage, but I thought that it may be useful from a 'logic' point of view.
I have tried to insert a WHILE clause into various locations within the Static Pivot query that I wrote, however in each instance there were errors produced by SSMS.
If anybody can suggest a way to solve my data pivoting challenge it will be much appreciated.
Kind Regards,
David
Challenge with Pivoting data
Hopefully, this will help
Create Table Foo(ItemCode varchar(6), ItemDescription varchar(50), OrderQty decimal(12,6), BinLabel varchar(7), BinQty decimal(12,6));
Insert Foo(ItemCode, ItemDescription, OrderQty, BinLabel, BinQty) Values
('DR1124', 'D6 Series 24 OD 3/8 1 Neck', 50, 'B1A1904', 9),
('DR1124', 'D6 Series 24 OD 3/8 1 Neck', 50, 'M1D0703', 66),
('DR1124', 'D6 Series 24 OD 3/8 1 Neck', 50, 'S1K0603', 24),
('H21', 'Rubber Mallot', 75, 'X1X0712', 100),
('H21', 'Rubber Mallot', 75, 'T3B4567', 92);
Declare @SQL nvarchar(max);
;With cteRN As
(Select ItemCode, ItemDescription, BinLabel, BinQty,
Row_Number() Over(Partition By ItemCode Order By BinLabel) As rn
From Foo)
Select @SQL = (Select Cast(N'' As nvarchar(max)) + N', Max(Case When rn = ' + Cast(rn As nvarchar(5)) + N' Then BinLabel End) As BinLabel' + Cast(rn As nvarchar(5))
+ N', Max(Case When rn = ' + Cast(rn As nvarchar(5)) + N' Then BinQty End) As BinQty' + Cast(rn As nvarchar(5))
From (Select Distinct rn From cteRN) x
Order By rn
For XML Path(''))
Select @SQL = Stuff(@SQL, 1, 2, '');
--Select @SQL
Select @SQL = N'Select ItemCode, Max(ItemDescription) As ItemDescription, Max(OrderQty) As OrderQty,' + @SQL + N' From (Select ItemCode, ItemDescription, OrderQty, BinLabel, BinQty,
Row_Number() Over(Partition By ItemCode Order By BinLabel) As rn
From Foo) As x Group By ItemCode'
--select @SQL
Exec(@SQL);
-- Cleanup
go
Drop Table Foo;
Tom
Challenge with Pivoting data
Hello Tom,
Thank you very much for responding to my post. I have adapted your example to fit with the databases that I am extracting data from. Here is the query that I have written (so far)...
DECLARE @SQL nvarchar(max);
;
WITH cteRN AS
(
SELECT
T0.ItemCode
, T0.ItemName
, T1.BINLABEL AS Binlabel
, T1.QUANTITY AS BinQty
, ROW_NUMBER()
OVER(PARTITION BY T0.ItemCode ORDER BY T1.BINLABEL) AS rn
FROM OITM T0
LEFT JOIN A1Warehouse..BINLOCAT T1 ON T1.PRODUCT = T0.ItemCode collate SQL_Latin1_General_CP850_CI_AS
)
SELECT @SQL = (
SELECT
CAST('' AS nvarchar(max)) + ', MAX(CASE WHEN rn = ' + CAST(rn AS nvarchar(5)) + ' THEN BinLabel END) As Binlabel' + CAST(rn AS nvarchar(5))
+ ', MAX(CASE WHEN rn = ' + CAST(rn AS nvarchar(5)) + ' THEN BinQty END) AS BinQty' + CAST(rn AS nvarchar(5))
FROM
(
SELECT DISTINCT rn FROM cteRN
)x
ORDER BY rn
FOR XML PATH(''))
SELECT @SQL = STUFF(@SQL, 1, 2, '');
SELECT @SQL =
'SELECT
Tx.ItemCode
, Max(Tx.ItemName) AS Description
,' + @SQL + '
FROM
(
SELECT
T0.ItemCode
, T0.ItemName
, T1.BINLABEL AS Binlabel
, T1.QUANTITY AS BinQty
, ROW_NUMBER()
OVER(PARTITION BY T0.ItemCode ORDER BY T1.BINLABEL) AS rn
FROM
OITM T0
LEFT JOIN A1Warehouse..BINLOCAT T1 ON T1.PRODUCT = T0.ItemCode collate SQL_Latin1_General_CP850_CI_AS
) AS Tx
GROUP BY Tx.ItemCode'
Exec(@SQL);
The results of the query above look like so -
There are many NULLs in the output, and I would like to remove these. However to be completely honest I do not know where to start with regards to removing them. I only started with T-SQL earlier this year and I do not fully understand everything that is taking place in the query. I am very comfortable with SELECT, and have a working understanding of the ROW_NUMBER() function, which I have used before on several occasions (though admittedly not quite like this) however I don't have any understanding of the following
- How you can 'assign' multiple values to the @SQL variable (if that is indeed what is happening)
- What 'FOR XML PATH('') actually does
- Dynamic SQL in general...
Ultimately I have a long way to come before I am truly comfortable with this query, however if you could share some insights into how I can go about removing the NULLs it will be greatly appreciated.
Thanks again.
Kind Regards,
David