Delete Rows with specified data
hello
maybe you know what script/formula i can use to do the following:
i need to remove rows what include in any cell some specified word.
words for lookup should be specified in another cells.
this require new script? or somebody know how to do this?
First, you cannot "delete" a row using a formula. You can make it so a row can be hidden. You can highlight a row (i.e., such as by putting the word "DELETE" in a cell in a particular column) so you can locate and delete the row manually. You could probably write a script to do these deletions for you but I'm not sure it is worth the time unless you need to do an awful lot of them or need to do it often.
The problem statement is still not completely clear. Will you be searching for the entire phrase "T-Technologies :: CODE3290"? Is that the entirety of what is in a cell or is that only part of the text in the cell? Or will you be searching for a piece of that phrase, such as "Technologies" or "Tech" or "code" or "3290"?
You can highlight any cell containing a particular word or phrase or group of letter/numbers by using conditional formatting. Use the test "text contains..." and type in the word you are looking for. Set the fill to red so you can see it. Use Copy Style then Paste Style to the rest of the table. Then manually delete any row that has a red cell.
Message was edited by: Badunit
Similar Messages
-
Deadlock when delete rows with blob.
Hello
I have the following issue. I try to clean a table that contains a BLOB column.
To do this I use SQLDBC I create a statement that contains the LOB column, I fetch the line, load the Blob. and before fetching the next line, I send a delete request. and I fall in the deadlock.
If I fetch the next line before sending the delete request there is no deadlock, there is also no deadlock if i do not request le LOB column in the select.
In fact when I made select with LOB, there is the follwing line in DOMAIN.LOCKS
SESSION;TRANSCOUNT;PROCESS;USERNAME;DATE;TIME;TERMID;LASTWRITE;LOCKMODE;LOCKSTATE;APPLPROCESS;APPLNODE;SCHEMANAME;OWNER;TABLENAME;TABLEID;ROWIDLENGTH;ROWIDHEX;ROWID;
295513; 4290;438;ESKDBADM;2010-06-17;12:05:46;ly-delorme-u..1674;?;tab_share;?;5748;LY-DELORME.esker.corp;?;?;?;0000800000046919;0;?;?
when i send the delete request the following lock appears in DOMAIN.LOCKS. A exclusif lock on the column I want to delete. It's ok
SESSION;TRANSCOUNT;PROCESS;USERNAME;DATE;TIME;TERMID;LASTWRITE;LOCKMODE;LOCKSTATE;APPLPROCESS;APPLNODE;SCHEMANAME;OWNER;TABLENAME;TABLEID;ROWIDLENGTH;ROWIDHEX;ROWID;
295521; 4287;167;ESKDBADM;2010-06-17;12:05:49;ly-delorme-u..1674; 5;row_exclusive;write;5748;LY-DELORME.esker.corp;ESKDBADM;ESKDBADM;DBM350_AUTOTESTXML;0000000000000934;5;00C51133800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
BUT there is a dead lock , I think because of the following entry in DOMAIN.LOCK_WAITS
TABLENAME;TABLEID;H_TERMID;H_PROCESS;H_APPLPROCESS;H_APPLNODE;H_ROWIDHEX;H_ROWID;H_LOCKMODE;H_DATE;H_TIME;H_LOCKTIMEOUT;R_TERMID;R_PROCESS;R_APPLPROCESS;R_APPLNODE;R_ROWIDHEX;R_ROWID;R_REQMODE;R_DATE;R_TIME;R_REQTIMEOUT;
?;0000800000046919;ly-delorme-u..1674;438;5748;LY-DELORME.esker.corp;?;?;tab_share;2010-06-17;12:05:46;?;ly-delorme-u..1674;167;5748;LY-DELORME.esker.corp;?;?;tab_exclusive;2010-06-17;12:05:49; 3585
The database request a tab_exclusive lock on tableid 0000800000046918 but there is already a tab_share lock on this.
Do you why there is a lock on the table : tableid 0000800000046918 ?
How to avoid this lock using SQLDBC ?
Thanks for you help.
Yann.this is the same reply as previous reply, this carriage return. I hope.
Hello,
Here is code that explain my issue.
I create a table like this :
create table "ESKDBADM"."DBM350_AUTOTESTXML"( "MSN" INTEGER not null, "DIST_FILE" BLOB, constraint SYSPRIMARYKEY primary key ("MSN"))
And then I try to delete row with the following program. I do not understand why the request SELECT Msn, DIST_FILE FROM DBM350_AUTOTESTXML set a share lock on the tableid : 000080000004691D.
I do not find this tableid in the "SYSINFO"."FILES" table.
SESSION;TRANSCOUNT;PROCESS;USERNAME;DATE;TIME;TERMID;LASTWRITE;LOCKMODE;LOCKSTATE;APPLPROCESS;APPLNODE;SCHEMANAME;OWNER;TABLENAME;TABLEID;ROWIDLENGTH;ROWIDHEX;ROWID;
295697; 5220;172;ESKDBADM;2010-06-21;11:01:40;ly-delorme-u..1CDC;?;tab_share;?;7388;LY-DELORME.esker.corp;?;?;?;000080000004691D;0;?;?
// SQLDBC.cpp : Defines the entry point for the console application.
// YOU MUST CHANGE CONNECTION SETTINGS.
#include "stdafx.h"
#include <stdio.h>
#include <tchar.h>
#include <comdef.h>
#include <iostream>
#include "SQLDBC.h"
using namespace SQLDBC;
static void parseArgs(int argc, wchar_t **argv);
static SQLDBC_Connection *connectDB(SQLDBC_Environment * env = NULL);
static char* convertToUCS2(char *src);
static void usage();
SQLDBC_Environment *g_env;
typedef struct ConnectArgsT {
bstrt username;
bstrt password;
bstrt dbname;
bstrt host;
bstrt request;
} ConnectArgsT;
ConnectArgsT connectArgs;
void exitOnError(SQLDBC_ErrorHndl &err);
int _tmain(int argc, _TCHAR* argv[])
parseArgs(argc, argv);
SQLDBC_Connection *conn = connectDB();
//* Create a new statment object and execute it.
SQLDBC_PreparedStatement *stmt = conn->createPreparedStatement();
// FREEZE
if (connectArgs.request.length() == 0)
connectArgs.request = "SELECT Msn, DIST_FILE FROM DBM350_AUTOTESTXML";
/* NO FREEZE
if (connectArgs.request.length() == 0)
connectArgs.request = "SELECT Msn FROM DBM350_AUTOTESTXML";
char command = (char)((LPCWSTR)(connectArgs.request));
//* Executes the UNICODE encoded SQL command.
SQLDBC_Retcode ret = stmt->prepare((const char*)command, SQLDBC_StringEncodingType::UCS2Swapped);
exitOnError(stmt->error());
stmt->execute();
exitOnError(stmt->error());
// * Get the resultset.
SQLDBC_ResultSet *result;
result = stmt->getResultSet();
exitOnError(stmt->error());
// * Fetch the row from the resultset.
result->next();
SQLDBC::SQLDBC_RowSet* pRowset = result->getRowSet();
ret = pRowset->fetch();
exitOnError(result->error());
wchar_t szString[30];
SQLDBC_Length ind;
Get a string value from the column.
result->getObject(1, SQLDBC_HOSTTYPE_UCS2_SWAPPED, szString, &ind, sizeof(szString)); // Retreive MSN.
// Delete de line.
// Create a new connection for delete
SQLDBC_Connection *conn2 = connectDB(g_env);
//* Create a new statment object and execute it.
SQLDBC_PreparedStatement *stmt2 = conn2->createPreparedStatement();
std::wstring st = L"DELETE FROM DBM350_AUTOTESTXML WHERE MSN=";
st += szString;
stmt2->prepare((char*)st.c_str(), SQLDBC_StringEncodingType::UCS2Swapped);
//* Executes the UNICODE encoded SQL command.
ret = stmt2->execute();
exitOnError(stmt->error());
printf("%s\n", szString);
return 0;
static char *convertToUCS2(char *src)
int len = strlen(src);
wchar_t w=(wchar_t)calloc(len, sizeof(wchar_t));
int nc = mbstowcs(w, src, len);
if ((size_t)-1 == nc) {
fprintf(stderr, "Conversion to UCS2 failed. Execution stopped.\n");
exit(1);
short s=(SQLDBC_Int2)calloc(nc+1, sizeof(SQLDBC_Int2));
int i;
for(i=0; i<nc; i++) {
s<i> = w<i>;
free(w);
return (char*)s;
static char* strupper(char *str)
char *p=str;
while(*p) {
p=toupper(p);
++p;
return str;
static wchar_t *argv0;
#ifdef WIN32
#define STRICMP _stricmp
#else
#define STRICMP strcasecmp
#endif
SQLDBC_Connection *connectDB(SQLDBC_Environment * env)
char errorText[200];
SQLDBC_Retcode rc;
if (g_env == NULL)
Every application has to initialize the SQLDBC library by getting a
reference to the ClientRuntime and calling the SQLDBC_Environment constructor.
SQLDBC_IRuntime *runtime;
runtime = SQLDBC::GetClientRuntime(errorText, sizeof(errorText));
if (!runtime) {
fprintf(stderr, "Getting instance of the ClientRuntime failed %s\n", errorText);
usage();
env = new SQLDBC_Environment(runtime);
g_env = env;
Create a new connection object and open a session to the database.
SQLDBC_Connection *conn = env->createConnection();
printf("Connecting to '%s' on '%s' as user '%s'\n",
(char)connectArgs.dbname, (char)connectArgs.host, (char*)connectArgs.username);
rc = conn->connect(connectArgs.host, connectArgs.dbname,
connectArgs.username, connectArgs.password);
if(SQLDBC_OK != rc) {
fprintf(stderr, "Can't connect to '%s'.\nERROR: %d:'%s'\n",
connectArgs.dbname, conn->error().getErrorCode(), conn->error().getErrorText());
exit(1);
return conn;
static void parseArgs (int argc, wchar_t **argv)
argv0 = wcsdup(argv[0]);
setting defaults for demo database
connectArgs.username = "ESKDBADM";
connectArgs.password = "DELORME";
connectArgs.dbname = "EDP350";
connectArgs.host = "ly-delorme";
use values from command line
if (argc > 5) {
connectArgs.request = argv [5];
if (argc > 4) {
connectArgs.host = argv [4];
if (argc > 3) {
connectArgs.dbname = argv [3];
if (argc > 2) {
connectArgs.password = argv [2];
if (argc > 1) {
if (!wcsicmp(argv [1], L"-h"))
usage();
else {
connectArgs.username = argv [1];
strupper(connectArgs.username);
strupper(connectArgs.password);
void exitOnError(SQLDBC_ErrorHndl &err)
if(err) {
fprintf(stderr, "Execution stopped %d:'%s'", err.getErrorCode(), err.getErrorText());
exit(1);
static void usage()
wchar_t *s = wcsrchr(argv0, L'/');
if (!s)
s = wcsrchr(argv0, L'
if (s)
*s = '\0';
printf("Syntax: %s [-h] | [<connect_options>]\n"
"\tconnect_options :: \n"
"\t\t[ <username> \n"
"\t\t[ <password>\n"
"\t\t[ <database_name>\n"
"\t\t[ <database_server> ]]]]\n"
"\t\t[ <request> ]]]]\n"
"\tCalling %s without any arguments will use user '%s','%s'\n"
"\t\ton database '%s' at server '%s'\n",
argv0, argv0,
connectArgs.username, connectArgs.password,
connectArgs.dbname, connectArgs.host);
exit(1); -
Deleting rows with missing values in field in start routine of update rule
Hello experts,
how can I delet rows with missing values in a specific field in the start routine of update rules?
I think ABAP code should look something like this:
delete ... from DATA_PACKAGE where Z_NO = ''.
thanks in advance for any suggestions!
hizaWrite:
delete data_package where field = value.
Hope it helps.
Regards -
Dear All,
I am trying to delete few rows, which have date and timestamp. I was able to delete the rows except dates with timestamp "12:00:00 PM". I even tried the "trunc" function. Please find the sample data below.
GC_ID--------COMPANY_ID......TRANSACTION_DATE----------TRANSACTION_CODE
14558-----------101350-------------1/31/2009 12:00:00 PM-------------6550
14528-----------101080-------------1/31/2009 12:00:00 PM-------------1510
14308-----------101510-------------1/31/2009 12:00:00 PM-------------1511
14308-----------101510-------------1/31/2009 12:00:00 PM-------------1506
14818-----------101611-------------1/31/2009 12:00:00 PM-------------1511
With Regards
PhaniIf you want to be precise and have other rows where seconds and minutes are specified then specify "AM" in the format mask, as follows;
create table t
(gc_id number
,company_id number
,transaction_date timestamp
,transaction_code number
insert into t values (14558, 101350, to_timestamp('01/31/2009 12:00:00 PM', 'mm/dd/yyyy hh12:mi:ss AM'), 6550)
delete from t where transaction_date = to_timestamp ('01/31/2009 12:00:00 PM', 'mm/dd/yyyy hh12:mi:ss AM')
/or better still use;
'01/31/2009 12:00:00', 'mm/dd/yyyy hh24:mi:ss' -
Not Getting Rows With No Date Match
I have SQL 2012 and am trying to use a CTE to get patient meal calendar rows even if the row does not match a given date range. We use a Calendar table that has 1 row for each date in the year so I wanted it to drive the results so that when I ask for a
week date range I will get rows even if the patient does not have a meal or snack scheduled for that date. My CTE code is below and it gives me the correct data but only if the patient has a meal or snack scheduled for that date (this is like a weekly
meal menu). Any help is appreciated.
ALTER PROCEDURE [dbo].[kd_selMealPlannerMatrix]
@PatientID int,
@StartDate smalldatetime,
@EndDate smalldatetime = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF @EndDate IS NULL
BEGIN
SET @EndDate = DATEADD(day,6,@StartDate);
END
;WITH client_meals AS (
SELECT DATEPART(dw, dbo.tblMealCalendar.MealDate) AS PrintDate,
dbo.tlkpMealCodes.MealCode,
CASE WHEN dbo.tblMealCalendar.MealID <> 0 THEN dbo.tblActualMeals.MealName + N' - ' + CONVERT(nvarchar, dbo.tblActualMeals.MealNumber)
WHEN dbo.tblMealCalendar.SnackID <> 0 THEN dbo.tblActualSnacks.SnackName + N' - ' + CONVERT(nvarchar, dbo.tblActualSnacks.SnackNumber)
ELSE NULL
END AS PrintMeal,
dbo.tblMealCalendar.PatientID,
dbo.tblMealCalendar.MealDate,
dbo.tblMealCalendar.CalendarID,
dbo.tlkpMealCodes.MealCodeSort,
dbo.tblActualMeals.MealID,
dbo.tblActualSnacks.SnackID,
dbo.tblMealCalendar.MealCodeID
FROM dbo.tblMealCalendar LEFT OUTER JOIN
dbo.tblActualMeals ON dbo.tblMealCalendar.MealID = dbo.tblActualMeals.MealID LEFT OUTER JOIN
dbo.tblActualSnacks ON dbo.tblMealCalendar.SnackID = dbo.tblActualSnacks.SnackID LEFT OUTER JOIN
dbo.tlkpMealCodes ON dbo.tblMealCalendar.MealCodeID = dbo.tlkpMealCodes.MealCodeID
WHERE (dbo.tblActualSnacks.Verified IS NULL OR dbo.tblActualSnacks.Verified <> 0)
AND (dbo.tblActualMeals.Verified IS NULL OR dbo.tblActualMeals.Verified <> 0)
AND (dbo.tblMealCalendar.PatientID = @PatientID)
), dt_range AS (
SELECT dt, DW
FROM dbo.Calendar
WHERE dt BETWEEN @StartDate AND @EndDate
SELECT
MAX(M.MealDate) AS MealDate,
MAX(M.PrintDate) AS PrintDay,
MAX(D.DW) AS WkDay,
MAX(CASE WHEN MealCode = 'AM Meal' THEN PrintMeal
ELSE NULL
END) AS AMMeal,
MAX(CASE WHEN MealCode = 'AM Meal' THEN MealID
ELSE 0
END) AS AMMealID,
MAX(CASE WHEN MealCode = 'AM Snack' THEN PrintMeal
ELSE NULL
END) AS AMSnack,
MAX(CASE WHEN MealCode = 'AM Snack' THEN SnackID
ELSE 0
END) AS AMSnackID,
MAX(CASE WHEN MealCode = 'Mid-Day' THEN PrintMeal
ELSE NULL
END) AS MidDay,
MAX(CASE WHEN MealCode = 'Mid-Day' THEN MealID
ELSE 0
END) AS MidDayMealID,
MAX(CASE WHEN MealCode = 'PM Snack' THEN PrintMeal
ELSE NULL
END) AS PMSnack,
MAX(CASE WHEN MealCode = 'PM Snack' THEN SnackID
ELSE 0
END) AS PMSnackID,
MAX(CASE WHEN MealCode = 'PM Meal' THEN PrintMeal
ELSE NULL
END) AS PMMeal,
MAX(CASE WHEN MealCode = 'PM Meal' THEN MealID
ELSE 0
END) AS PMMealID,
MAX(CASE WHEN MealCode = 'Evening Snack' THEN PrintMeal
ELSE NULL
END) AS EveningSnack,
MAX(CASE WHEN MealCode = 'Evening Snack' THEN SnackID
ELSE 0
END) AS EveningSnackID,
MAX(CASE WHEN MealCode = '4th Meal' THEN PrintMeal
ELSE NULL
END) AS FourthMeal,
MAX(CASE WHEN MealCode = '4th Meal' THEN MealID
ELSE 0
END) AS FourthMealID
FROM dt_range AS D RIGHT OUTER JOIN
client_meals AS M ON D.dt = M.MealDate
GROUP BY D.dt
HAVING (D.dt BETWEEN @StartDate AND @EndDate)
ORDER BY D.dt;
ENDI tried to keep this as close to what we know as I could. Here's an example of making it work as you're asking:
DECLARE @tinyCalendar table (date date)
DECLARE @i INT = 0
WHILE @i < 10
BEGIN
INSERT INTO @tinyCalendar (date)
VALUES (DATEADD(DAY,-@i,GETDATE()))
SET @i = @i + 1
END
DECLARE @patients TABLE (id INT IDENTITY, name VARCHAR(20))
INSERT INTO @patients (name)
VALUES ('John'),('Paul'),('George'),('Ringo')
DECLARE @mealSelections TABLE (patientID INT, mealID INT, mealCode VARCHAR(8), DATE DATE)
INSERT INTO @mealSelections (patientID, mealID, mealCode, date)
VALUES
(1,1,'1st Meal','2014-08-12'),(1,2,'1st Meal','2014-08-13'),(1,3,'1st Meal','2014-08-14'),(1,4,'1st Meal','2014-08-15'),(2,1,'1st Meal','2014-08-12'),(2,2,'1st Meal','2014-08-13'),(2,3,'1st Meal','2014-08-14'),(2,4,'1st Meal','2014-08-15'),(3,1,'1st Meal','2014-08-12'),(3,2,'1st Meal','2014-08-13'),(3,3,'1st Meal','2014-08-14'),(3,4,'1st Meal','2014-08-15'),(4,1,'1st Meal','2014-08-12'),(4,2,'1st Meal','2014-08-13'),(4,3,'1st Meal','2014-08-14'),(4,4,'1st Meal','2014-08-15'),
(1,1,'1st Meal','2014-08-16'),(1,2,'1st Meal','2014-08-17'),(1,3,'1st Meal','2014-08-18'),(1,4,'1st Meal','2014-08-19'),(2,1,'1st Meal','2014-08-16'),(2,2,'1st Meal','2014-08-17'),(2,3,'1st Meal','2014-08-18'),(2,4,'1st Meal','2014-08-19'),(3,1,'1st Meal','2014-08-16'),(3,2,'1st Meal','2014-08-17'),(3,3,'1st Meal','2014-08-18'),(3,4,'1st Meal','2014-08-19'),(4,1,'1st Meal','2014-08-16'),(4,2,'1st Meal','2014-08-17'),(4,3,'1st Meal','2014-08-18'),(4,4,'1st Meal','2014-08-19'),
(1,1,'2nd Meal','2014-08-12'),(1,2,'2nd Meal','2014-08-13'),(1,3,'2nd Meal','2014-08-14'),(1,4,'2nd Meal','2014-08-15'),(2,1,'2nd Meal','2014-08-12'),(2,2,'2nd Meal','2014-08-13'),(2,3,'2nd Meal','2014-08-14'),(2,4,'2nd Meal','2014-08-15'),(3,1,'2nd Meal','2014-08-12'),(3,2,'2nd Meal','2014-08-13'),(3,3,'2nd Meal','2014-08-14'),(3,4,'2nd Meal','2014-08-15'),(4,1,'2nd Meal','2014-08-12'),(4,2,'2nd Meal','2014-08-13'),(4,3,'2nd Meal','2014-08-14'),(4,4,'2nd Meal','2014-08-15'),
(1,1,'2nd Meal','2014-08-16'),(1,2,'2nd Meal','2014-08-17'),(1,3,'2nd Meal','2014-08-18'),(1,4,'2nd Meal','2014-08-19'),(2,1,'2nd Meal','2014-08-16'),(2,2,'2nd Meal','2014-08-17'),(2,3,'2nd Meal','2014-08-18'),(2,4,'2nd Meal','2014-08-19'),(3,1,'2nd Meal','2014-08-16'),(3,2,'2nd Meal','2014-08-17'),(3,3,'2nd Meal','2014-08-18'),(3,4,'2nd Meal','2014-08-19'),(4,1,'2nd Meal','2014-08-16'),(4,2,'2nd Meal','2014-08-17'),(4,3,'2nd Meal','2014-08-18'),(4,4,'2nd Meal','2014-08-19'),
(1,1,'3rd Meal','2014-08-12'),(1,2,'3rd Meal','2014-08-13'),(1,3,'3rd Meal','2014-08-14'),(1,4,'3rd Meal','2014-08-15'),(2,1,'3rd Meal','2014-08-12'),(2,2,'3rd Meal','2014-08-13'),(2,3,'3rd Meal','2014-08-14'),(2,4,'3rd Meal','2014-08-15'),(3,1,'3rd Meal','2014-08-12'),(3,2,'3rd Meal','2014-08-13'),(3,3,'3rd Meal','2014-08-14'),(3,4,'3rd Meal','2014-08-15'),(4,1,'3rd Meal','2014-08-12'),(4,2,'3rd Meal','2014-08-13'),(4,3,'3rd Meal','2014-08-14'),(4,4,'3rd Meal','2014-08-15'),
(1,1,'3rd Meal','2014-08-16'),(1,2,'3rd Meal','2014-08-17'),(1,3,'3rd Meal','2014-08-18'),(1,4,'3rd Meal','2014-08-19'),(2,1,'3rd Meal','2014-08-16'),(2,2,'3rd Meal','2014-08-17'),(2,3,'3rd Meal','2014-08-18'),(2,4,'3rd Meal','2014-08-19'),(3,1,'3rd Meal','2014-08-16'),(3,2,'3rd Meal','2014-08-17'),(3,3,'3rd Meal','2014-08-18'),(3,4,'3rd Meal','2014-08-19'),(4,1,'3rd Meal','2014-08-16'),(4,2,'3rd Meal','2014-08-17'),(4,3,'3rd Meal','2014-08-18'),(4,4,'3rd Meal','2014-08-19'),
(1,1,'4th Meal','2014-08-12'),(1,2,'4th Meal','2014-08-13'),(1,3,'4th Meal','2014-08-14'),(1,4,'4th Meal','2014-08-15'),(2,1,'4th Meal','2014-08-12'),(2,2,'4th Meal','2014-08-13'),(2,3,'4th Meal','2014-08-14'),(2,4,'4th Meal','2014-08-15'),(3,1,'4th Meal','2014-08-12'),(3,2,'4th Meal','2014-08-13'),(3,3,'4th Meal','2014-08-14'),(3,4,'4th Meal','2014-08-15'),(4,1,'4th Meal','2014-08-12'),(4,2,'4th Meal','2014-08-13'),(4,3,'4th Meal','2014-08-14'),(4,4,'4th Meal','2014-08-15'),
(1,1,'4th Meal','2014-08-16'),(1,2,'4th Meal','2014-08-17'),(1,3,'4th Meal','2014-08-18'),(1,4,'4th Meal','2014-08-19'),(2,1,'4th Meal','2014-08-16'),(2,2,'4th Meal','2014-08-17'),(2,3,'4th Meal','2014-08-18'),(2,4,'4th Meal','2014-08-19'),(3,1,'4th Meal','2014-08-16'),(3,2,'4th Meal','2014-08-17'),(3,3,'4th Meal','2014-08-18'),(3,4,'4th Meal','2014-08-19'),(4,1,'4th Meal','2014-08-16'),(4,2,'4th Meal','2014-08-17'),(4,3,'4th Meal','2014-08-18'),(4,4,'4th Meal','2014-08-19')
SELECT p.id, p.name, c.date,
Max(CASE WHEN mealCode = '1st Meal' THEN mealID END) AS FirstMeal,
Max(CASE WHEN mealCode = '2nd Meal' THEN mealID END) AS SecondMeal,
Max(CASE WHEN mealCode = '3rd Meal' THEN mealID END) AS ThirdMeal,
Max(CASE WHEN mealCode = '4th Meal' THEN mealID END) AS FourthMeal
FROM @patients p
INNER JOIN @tinyCalendar c
ON p.id = p.id
LEFT OUTER JOIN @mealSelections m
ON p.id = m.patientID
AND m.date = c.date
GROUP BY p.id, p.name, c.date
ORDER BY c.date -
Deleting rows with child records
Hi,
I want to delete some records from master table based on where condition. But I want all the corresponding child record should also delete from the respective child tables..
Can anyone tell me how to go about it with example( eg emp & dept table of scotts)
RegardsI have been to slow for posting...
Please note that I hate doing this
SCOTT@LSC01> select count(*) from emp;
COUNT(*)
14
SCOTT@LSC01> delete dept where deptno=10;
<font color=red>1 row deleted.</font>
SCOTT@LSC01> select count(*) from emp;
COUNT(*)
11the risk is that someone is not aware of deleting rows, and instead of getting
SCOTT@LSC01> delete dept where deptno=10;
delete dept where deptno=10
ERROR at line 1:
ORA-02292: integrity constraint (SCOTT.FK_DEPTNO) violated - child record foundhe is deleting rows in other tables and will never be aware of that deletion ... -
XML Query Help row with no data
declare @address table
AddressID int,
AddressType varchar(12),
Address1 varchar(20),
Address2 varchar(20),
City varchar(25),
AgentID int
insert into @address
select 1, 'Home', 'abc', 'xyz road', 'RJ', 1 union all
select 2, 'Office', 'temp', 'ppp road', 'RJ', 1 union all
select 3, 'Home', 'xxx', 'aaa road', 'NY', 2 union all
select 4, 'Office', 'ccc', 'oli Com', 'CL', 2 union all
select 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 union all
select 6, 'Home', 'ttt', 'loik road', 'NY', 3
SELECT a.* from @address a
where a.AddressID = 1
FOR XML path('Addresses')
SELECT a.* from @address a
where a.AddressID = 9
FOR XML path('Addresses')
Issue:
As you can see for second query where AddressID = 9 is not exists so xml is not generated but
my expected result is for second query is
<Addresses>
<AddressID />
<AddressType />
<Address1 />
<Address2 />
<City />
<AgentID />
</Addresses>
Thanks in advance for all your help.First of all: Your expectation is wrong. Sorry to say that. But your SQL statement for A.AddressID = 9 does not return a row. So no row is converted. I hope you C it: void.
From the XML viewpoint:
<Addresses>
<AddressID />
<AddressType />
<Address1 />
<Address2 />
<City />
<AgentID />
</Addresses>
is equivalent to
<Addresses />
which is equivalent to
void
You C. Sorry got infeCted some how ;)
The only meaningful result in XML would be:
<Addresses ID="1">
<AddressType>Home</AddressType>
<Address1>abc</Address1>
<Address2>xyz road</Address2>
<City>RJ</City>
<AgentID>1</AgentID>
</Addresses>
<Addresses ID="9"/>
Cause now Addresses (Really? A plural form for a single entity?) transports the meaning, well there is no data (no row) for it. We tried to find it, but we failed. In opposite to
<Addresses>
<AddressID>9</AddressID>
<AddressType />
<Address1 />
<Address2 />
<City />
<AgentID />
</Addresses>
<Addresses ID="9">
<AddressType />
<Address1 />
<Address2 />
<City />
<AgentID />
</Addresses>
Which says: well, we have a row with the ID 9, but the rest of the columns is empty.
The problem is mere semantics. But it's an important difference.
Now for your problem: Why do you expect this? Where do can you work with such a kind of informationless result?
btw, as you're using already a table variable (+1), you should also use
table value constructors like
INSERT INTO @address
VALUES ( 1, 'Home', 'abc', 'xyz road', 'RJ', 1 ),
( 2, 'Office', 'temp', 'ppp road', 'RJ', 1 ),
( 3, 'Home', 'xxx', 'aaa road', 'NY', 2 ),
( 4, 'Office', 'ccc', 'oli Com', 'CL', 2 ),
( 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 ),
( 6, 'Home', 'ttt', 'loik road', 'NY', 3 );
I would use a tally table, when you really need this:
DECLARE @address TABLE
AddressID INT ,
AddressType VARCHAR(12) ,
Address1 VARCHAR(20) ,
Address2 VARCHAR(20) ,
City VARCHAR(25) ,
AgentID INT
INSERT INTO @address
VALUES ( 1, 'Home', 'abc', 'xyz road', 'RJ', 1 ),
( 2, 'Office', 'temp', 'ppp road', 'RJ', 1 ),
( 3, 'Home', 'xxx', 'aaa road', 'NY', 2 ),
( 4, 'Office', 'ccc', 'oli Com', 'CL', 2 ),
( 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 ),
( 6, 'Home', 'ttt', 'loik road', 'NY', 3 );
WITH n1
AS ( SELECT *
FROM ( VALUES ( 1), ( 1), ( 1), ( 1) ) Q ( n )
n2
AS ( SELECT a.n
FROM n1 a ,
n1 b ,
n1 c ,
n1 d
NumberTally
AS ( SELECT ROW_NUMBER() OVER ( ORDER BY n ) AS n
FROM n2
SELECT NT.n AS [@ID] ,
a.AddressType ,
a.Address1 ,
a.Address2 ,
a.City ,
a.AgentID
FROM NumberTally NT
LEFT JOIN @address a ON a.AddressID = NT.n
WHERE NT.n IN ( 1, 9 )
FOR XML PATH('Address');
or the void version:
DECLARE @address TABLE
AddressID INT ,
AddressType VARCHAR(12) ,
Address1 VARCHAR(20) ,
Address2 VARCHAR(20) ,
City VARCHAR(25) ,
AgentID INT
INSERT INTO @address
VALUES ( 1, 'Home', 'abc', 'xyz road', 'RJ', 1 ),
( 2, 'Office', 'temp', 'ppp road', 'RJ', 1 ),
( 3, 'Home', 'xxx', 'aaa road', 'NY', 2 ),
( 4, 'Office', 'ccc', 'oli Com', 'CL', 2 ),
( 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 ),
( 6, 'Home', 'ttt', 'loik road', 'NY', 3 );
WITH n1
AS ( SELECT *
FROM ( VALUES ( 1), ( 1), ( 1), ( 1) ) Q ( n )
n2
AS ( SELECT a.n
FROM n1 a ,
n1 b ,
n1 c ,
n1 d
NumberTally
AS ( SELECT ROW_NUMBER() OVER ( ORDER BY n ) AS n
FROM n2
SELECT a.AddressID AS [@ID] ,
a.AddressType ,
a.Address1 ,
a.Address2 ,
a.City ,
a.AgentID
FROM NumberTally NT
LEFT JOIN @address a ON a.AddressID = NT.n
WHERE NT.n IN ( 1, 9 )
FOR XML PATH('Address'); -
Update row with more data - JTable with Abstracttablemodel
Hello!
I got some problems with my program, im using jtable with abstracttablemodel.
First I include content into the jtable by pressing ”New Content”, then it will pop up a dialog which I fill with information as you can see in the picture.
http://img42.imageshack.us/img42/6969/jtable.jpg
But when its done, I want to borrow it and update that row with more information as you can see if its loaned, if it is their shall be a checkbox, name and phone there. I don’t really know how to do this. Suppose I should do a similar metodh as when I’m adding and removing content. The question is how do I do that? I’ve been looking at some tips and hints on google. It seems to me that should use “fireTableRowsUpdated” but not really sure if its right and how to. When I’m borrowing the specific row I guess I need to check which row is clicked before borrowing and then fill in the information and update the table.The borrow button will also pop up a dialog with 3 fields to fill. Here is the code I wrote for adding and removing. I’ve tried with the update but its not right which I’m going to use when borrowing objects from the database. Please help!
Code from the abstracttablemodel
private ArrayList<Objects> obj = new ArrayList<Objects>();
public void add(Objects o) {
obj.add(o);
fireTableRowsInserted(obj.size()-1, obj.size()-1);
public void remove(int o) {
int index = obj.indexOf(o);
obj.remove(o);
fireTableRowsDeleted(index, index);
public void update (Objects o){
// Not sure how to do here
//int index = obj.indexOf(o);
//fireTableRowsUpdated(index,index);
}Code for the button in the main program.
if (arg.getSource() == borrow) {
// How should I do here? I need to implement the BorrowDialog, check if a row is pressed then update? How do I do that?
BorrowDialog newLoan = new BorrowDialog(frame);
if(table.getSelectedRow() == -1)
JOptionPane.showMessageDialog(frame,"Select the row before loan");
else
dir.update(newLoan.getLoan());
table.repaint();
}Code for BorrowDialog
public class BorrowDialog extends JDialog implements ActionListener {
//implements JTextFields, Buttons,Labels and Panels.
public BorrowDialog(JFrame parent) {
//Setting buttons to panels and such
public Objects getLoan(){
return loan;
public void setLoan()
// Not sure if this is right, as I leave some fields empty, will it be empty when its updating aswell?
// I tried with add data then it just will be a new row, when I will update a specific row
loan = new Objects("", "" , "" , "" , "" ,"", loanField.getText(),nameField.getText(), phoneField.getText());
public void actionPerformed(ActionEvent arg) {
if (arg.getActionCommand().equals("Save")) {
System.out.println("save");
setLoan();
dispose();
}All help is appreciated!
Edited by: iTech34 on Feb 22, 2010 3:27 AM
Edited by: iTech34 on Feb 22, 2010 3:31 AM
Edited by: iTech34 on Feb 22, 2010 3:58 AMLook up for the rest of the code!
I explained everything on the first post, so please read there so you know the problem I got.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Database implements ActionListener {
private final int WIDTH = 800;
private final int HEIGHT = 800;
private JTable table = new JTable();
private JFrame frame = new JFrame("Database");
private JButton addContent = new JButton("New content");
private JButton borrow = new JButton("Borrow");
private JButton returnObject = new JButton("Return");
private JButton remove = new JButton("Remove");
private JButton save = new JButton("Save");
private JButton load = new JButton("Load");
private JButton exit = new JButton("Exit");
private Directory dir = new Directory();
private JPanel buttonPanel = new JPanel();
private JPanel mainPanel = new JPanel();
public Database() {
// BUTTONS
buttonPanel.add(addContent);
buttonPanel.add(remove);
buttonPanel.add(borrow);
buttonPanel.add(returnObject);
buttonPanel.add(save);
buttonPanel.add(load);
buttonPanel.add(exit);
// ACTION LISTENERS
addContent.addActionListener(this);
remove.addActionListener(this);
borrow.addActionListener(this);
returnObject.addActionListener(this);
save.addActionListener(this);
load.addActionListener(this);
exit.addActionListener(this);
// JTABLE
table = new JTable(dir);
table.setAutoCreateRowSorter(true);
table.setRowHeight(25);
JScrollPane JScroll = new JScrollPane(table);
// PANELS
mainPanel.setLayout(new BorderLayout());
mainPanel.add("North", buttonPanel);
mainPanel.add("Center", JScroll);
// FRAME
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public void actionPerformed(ActionEvent arg) {
if (arg.getSource() == addContent) {
Dialog newDialog = new Dialog(frame);
dir.add(newDialog.getItem());
if (arg.getSource() == remove) {
if (table.getSelectedRow() == -1)
JOptionPane.showMessageDialog(frame,"Select the row before remove");
else
dir.remove(table.getSelectedRow());
if (arg.getSource() == borrow) {
// Not sure how to do here! I need to check which row I've clicked and take that row into BorrowDialog as argument i suppose.. please explain
BorrowDialog newLoan = new BorrowDialog(frame);
if(table.getSelectedRow() == -1)
JOptionPane.showMessageDialog(frame,"Select the row before loan");
else
dir.update(newLoan.getLoan());
table.repaint();
if (arg.getSource() == returnObject) {
if (arg.getSource() == save) {
dir.writeFile();
if (arg.getSource() == load) {
Objects[] tempObject = dir.readFile("info.txt");
for (int i = 0; tempObject[i] != null; i++)
dir.add(tempObject);
if (arg.getSource() == exit){
frame.dispose();
public static void main(String[] argv) {
new Database();
}import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class BorrowDialog extends JDialog implements ActionListener {
private final int WIDTH = 300;
private final int HEIGHT = 400;
private JButton exitDialog = new JButton("Exit");
private JButton saveDialog = new JButton("Save");
private JTextField loanField = new JTextField();
private JTextField nameField = new JTextField();
private JTextField phoneField = new JTextField();
private JLabel loanLabel = new JLabel("Loan");
private JLabel nameLabel = new JLabel("Name");
private JLabel phoneLabel = new JLabel("Phone");
private JPanel eastPanel = new JPanel();
private JPanel southPanel = new JPanel();
private JPanel westPanel = new JPanel();
private GridLayout layout = new GridLayout(3, 1);
private Objects loan;
public BorrowDialog(JFrame parent) {
super(parent, "Borrow", true);
southPanel.add(saveDialog);
southPanel.add(exitDialog);
westPanel.add(loanLabel);
eastPanel.add(loanField);
westPanel.add(nameLabel);
eastPanel.add(nameField);
westPanel.add(phoneLabel);
eastPanel.add(phoneField);
westPanel.setLayout(layout);
eastPanel.setLayout(layout);
add("West", westPanel);
add("Center", eastPanel);
add("South", southPanel);
saveDialog.addActionListener(this);
exitDialog.addActionListener(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setResizable(false);
setSize(WIDTH, HEIGHT);
getContentPane();
setVisible(true);
public Objects getLoan(){
return loan;
public void setLoan()
// Can I really do like this? Will the the specific row I've chosen be overwriten entirly with blank elements in the six columns as I left empty(see below, when I send the arguments into the constructor)?
loan = new Objects("", "" , "" , "" , "" ,"", loanField.getText(),nameField.getText(), phoneField.getText());
public void actionPerformed(ActionEvent arg) {
if (arg.getActionCommand().equals("Save")) {
System.out.println("save");
setLoan();
dispose();
if (arg.getSource() == exitDialog) {
dispose();
Edited by: iTech34 on Feb 22, 2010 11:19 AM
Edited by: iTech34 on Feb 22, 2010 11:20 AM -
Dupekill - delete files with duped data (2012-06-13 update)
A few years ago, a friend and I had gotten a hold of a game's audio ripped directly from the disc. It included thousands of files that made up the game's sound, and many of the files sounded the exact same. We set out to pare this massive set of files down to something more manageable, with Python on our side. Thus, dupekill was born. When we first made it, it didn't recurse and was basically hacked together. I spent all of last night and most of this morning tweaking it for Python 3 and tried to turn it into a flexible console app/module.
dupekill will (by default) search the current directory for files with duplicated data and get rid of them. It accepts -h (help), -r (recursive), and -v (verbose) flags, which are obvious, and a path.
In addition, I added a "dry run" (-d) flag, so you know what will happen before you commit to getting rid of dupes. Without further delay, here it is:
https://github.com/sporkbox/dupekill
AUR Project Page
It's my first Python 3 app and the closest I've come to a truly useful piece of software.
Comments and suggestions welcome.
UPDATE (2011-11-04)
dupekill v1.3 is out. I followed keenerd's optimization suggestions to make it run better. Next on the list is an AUR package.
UPDATE (2012-06-12)
dupekill 1.5 supports ignoring symlinks with `-i`. Also available in the AUR.
UPDATE (2012-06-13)
dupekill 1.6
ignores device and character nodes as well as sockets and FIFO pipes.
`-a` and `-v` will now display the file that a dupe is a copy of, or the original file that a symlink clashes with.
Last edited by xelados (2012-07-25 17:43:49)keenerd wrote:
This sha256 sums every file. That could be quite slow. For example:
time find /{bin,opt,sbin,usr,lib,lib32,lib64,boot,etc} -xtype f -print0 | xargs -0 NNNsum > /dev/null
sha256sum - 153 seconds (user)
md5sum - 44 seconds (user)
head -c 512 - 2.5 seconds (user)
ls -l - 5.6 seconds (user)
User time ignores IO, but I ran all on cold caches to be safe.
Some suggestions for optimizations: first stat the files and get the total size. If the sizes match, then read and compare the first 512 bytes. If those match, then md5 the files. If those match, then sha512. (While head looks like a fast operation, comparing the 512 bytes is not, so it goes after the size.)
edit, added stats
If I understand correctly, the idea is to only use up resources when needed, correct? If two files are of a different size, then obviously their contents will differ, for instance. I tested dupekill on my music collection and it surely took a little while. I imagine checking simpler things would improve the speed of the system. Thanks for the suggestion! I'll see what I can do to introduce something like that in the next version.
Last edited by xelados (2011-10-19 11:40:15) -
SSRS Matrix Issue. Expression calculating in row with no data.
I have a matrix with multiple column groups for different sales channels. With in each group there are several columns and some with expressions for calculations. The rows are based on sales reps. Now not every sales rep sells in every channel, so there
are some columns in which a rep will have no data. I want them be blank or show a 0. I can do both of those. The issue I am having is in the expressions for reps that have no data, it is still showing a calculation. It seems to populate that cell with whatever
the first result of an actual calculation is. See below. For rep D and E they have no calls or sales in this particular sales channel; however, the closing ratio is showing 30.23% (which is the closing ratio for rep A). I need this to be blank or 0 or N/A,
anything other that a wrong %. I have tried numerous iif and isnothing statements, e.g. =iif(Fields!count_of_customers.Value = 0,0,Fields!count_of_customers.Value/iif(Fields!Calls.Value = 0,1,Fields!Calls.Value)) plus other i have found on the internet
but none of them work. Can someone please help? Sorry it is not a picture of the report. They need to confirm my account before I can attach pictures. But this is the set up of the report.
Figure A
Phone Field
Rep Calls
Sales Closing Ratio
Premium Rep
Calls Sales
A 1000
323 32.3%
$100,250 A
50 5
B 200
10 5% $50,000
B 0
0
C 300
15 5% $25,000
C 25
5
D 0
0 32.3%
$0 D
300 50
E 0
0 32.3%
$0 E
100 15
F 500
100 20%
$300,000 F
0 0Hi RobTencents,
After testing the issue in my environment, I can reproduce it. To fix this issue, please try to use the expression below to instead the original one:
=iif(sum(Fields!count_of_customers.Value) = 0,0,sum(Fields!count_of_customers.Value)/iif(sum(Fields!Calls.Value) = 0,1,sum(Fields!Calls.Value)))
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Using alternate rows with Spry Data Set
Can anyone provide more information on how to implement alternate row colors with a Spry Data Set? What I have done is:
Create spry data set using HTML page as the data set
The html page that displays the data set is: <div spry:region="equipment">
In the default.css page that is linked, I added the info in note #1 below
When the page displays, no colors appear. Tried changing the colors and still no luck. Is there another step to do?
Note #1:
within the default.css, the following are declared:
#equipment odd {
background-color: #CCC;
#equipment even {
background-color: “#F2F2F2;
Note #2:
Here is a link to see the actual pages referenced above.
Any ideas? Getting frustrated!! Thanks in advance for any advice.You are going to kick yourself, but, you haven't assigned any page element the ID #equipment. The region is called that but the table or the DIV does not have an idea and your selector matches nothing...
-
Deleting row with inputText components throws error:
How delete a row in table with inputText components in it?
I tried just deleting it from the model but then I get the following error:
javax.faces.el.EvaluationException: java.lang.IndexOutOfBoundsException: Index: 3, Size: 2oops. I posted to the wrong group. sorry. I've since moved it to jdeveler.
-
Cross Tab keeps suppressing rows with no data
I have a Crystal Report that is using a Cross Tab. I have 2 rows in the cross tab the first row is the Month name and the second row is the Day Number of the month, and the report will print the Month Name on the left followed by all the Calendar Day Numbers in the month.
The problem is that when there is no data for a Day Number row the entire row is not shown. So you might have day number 1, 2, 3 and then jumps to maybe 6. I found that the ones the cross tab was not showing did not contain any data. I just need the calendar day number to at least print so the days read sequentially instead of jumping to 6 or another number.
Is there any way to show the rows even if they don't contain any data?
I have right clicked and gone into the Cross Tab expert and there isn't anything checked to suppress rows. I don't understand why its still suppressing rows!
Is there a global report option that I missed that says "suppress rows when there are no records"?
Thank you all in advance,
I am using Crystal Reports XIR2 with Service Pack 4I am still not getting all rows to show up on the report. The rows that are not showing up contain no data in the cross tab but the row still needs to show.
The only reason I got it to work before was because I selected all values for the columns parameter so it brought back everything in the database that was why it was able to show all values.
I have two tables one is a date database and contains all the dates till 2012. The other is the product data which contains the product code and qty that the cross tab summarizes.
I have done a left outer join from the product data to the date database, and I am still not able to get all the dates to list for the selected time range.
I was able to get the dates to show up when I right clicked the link and modified the link properties. I chose Left Outer Join and then under Link Type I selected ">" in the database expert dialog. This brought back all the dates but the data in the report was all the same. Probably just the first record repeated all down the page.
Any ideas how to fix this problem? -
I have a problem, The scenario is that when I click any folder that si in my JTable's first row, the table is update by removing all the rows and showing only the contents of my selected folder. Right now it's not removing the rows and instead throwing exceptions. The code is attached. The methods to look are upDateTabel(...) and clearTableData(....), after clearing all my rows then I proceed on adding my data to the Jtable and inserting rows but it's not being done. May be I have a problem in my DefaultTableModel class. Please see the code below what I am doing wrong and how should I do it. Any help is appreciated.
Thanks
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class SimpleTable extends JPanel{
/** Formats the date */
protected SimpleDateFormat formatter;
/** variable to hold the date and time in a raw form for the directory*/
protected long dateDirectory;
/** holds the readable form converted date for the directories*/
protected String dirDate;
/** holds the readable form converted date for the files*/
protected String fileDate;
/** variable to hold the date and time in a raw form for the file*/
protected long dateFile;
/** holds the length of the file in bytes */
protected long totalLen;
/** convert the length to the wrapper class */
protected Long longe;
/** Vector to hold the sub directories */
protected Vector subDir;
/** holds the name of the selected directory */
protected String dirNameHold;
/** converting vector to an Array and store the values in this */
protected File directoryArray[];
/** hashtable to store the key-value pair */
protected static Hashtable hashTable = new Hashtable();
/** refer to the TableModel that is the default*/
protected MyTableModel tableModel;
/** stores the path of the selected file */
protected static String fullPath;
/** stores the currently selected file */
protected static File selectedFilename;
/** stores the extension of the selected file */
protected static String extension;
protected int COLUMN_COUNT = 4;
protected Vector data = new Vector( 0, 1 );
protected final JTable table;
/** holds the names of the columns */
protected final String columnNames[] = {"Name", "Size", "Type", "Modified"};
public SimpleTable(File directoryArray[])
this.setLayout(new BorderLayout());
this.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
(SimpleTable.hashTable).clear();
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data.addElement( new MyObj( directoryArray[k].getName(), "", "File Folder", "" + dirDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
else if(directoryArray[k].isFile())
dateDirectory = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateDirectory));
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data.addElement( new MyObj( directoryArray[k].getName(), longe + " Bytes", "", "" + fileDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
tableModel = new MyTableModel();
table = new JTable( tableModel );
table.getTableHeader().setReorderingAllowed(false);
table.setRowSelectionAllowed(false);
table.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
table.addMouseListener(new MouseAdapter()
public void mouseReleased(MouseEvent e)
Object eventTarget = e.getSource();
if( eventTarget == table )
upDateTable(table);
table.tableChanged( new javax.swing.event.TableModelEvent(tableModel) ) ;
DefaultTableCellRenderer D_headerRenderer = (DefaultTableCellRenderer ) table.getTableHeader().getDefaultRenderer();
table.getColumnModel().getColumn(0).setHeaderRenderer(D_headerRenderer );
((DefaultTableCellRenderer)D_headerRenderer).setToolTipText("File and Folder in the Current Folder");
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
this.add(scrollPane, BorderLayout.CENTER);
* Searches the Hashtable and returns the path of the folder or the value.
public File findPath(String value)
return (File)((SimpleTable.hashTable).get(value));
* This clears the previous data in the JTable
public void clearTableData(JTable table)
for(int row = 0; row < table.getRowCount() ; row++)
//for (int col = 0; col < table.getColumnCount() ; col++)
tableModel.deleteSelections( row );
tableModel.fireTableStructureChanged();
tableModel.fireTableRowsDeleted(0,table.getRowCount());
//table.getModel().fireTableChanged(new TableModelEvent(table.getModel()));
private void upDateTable(JTable table)
if((table.getSelectedColumn() == 0) && ((table.getColumnName(0)).equals(columnNames[0])))
dirNameHold =(String) table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
File argument = findPath(dirNameHold);
if(argument.isFile())
CMRDialog.fileNameTextField.setText(argument.getName());
try
fullPath = argument.getCanonicalPath();
selectedFilename = argument.getCanonicalFile();
CMRDialog.filtersComboBox.removeAllItems();
extension = fullPath.substring(fullPath.lastIndexOf('.'));
CMRDialog.filtersComboBox.addItem("( " + extension + " )" + " File");
catch(IOException e)
System.out.println("THE ERROR IS " + e);
return;
else if(argument.isDirectory())
String path = argument.getName();
//find the system dependent file separator
//String fileSeparator = System.getProperty("file.separator");
CMRDialog.driveComboBox.addItem(" " + path);
subDir = Search.subDirs(argument);
/**TBD:- needs a method to convert the vector to an array and return the array */
directoryArray = new File[subDir.size()];
int indexCount = 0;
/** TBD:- This is inefficient way of converting a vector to an array */
Iterator e = subDir.iterator();
while( e.hasNext() )
directoryArray[indexCount] = (File)e.next();
indexCount++;
/** now calls this method and clears the previous data */
clearTableData(table);
(SimpleTable.hashTable).clear();
//data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data.addElement( new MyObj( directoryArray[k].getName(), "", "File Folder", "" + dirDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
else if(directoryArray[k].isFile())
dateDirectory = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateDirectory));
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data.addElement( new MyObj( directoryArray[k].getName(), longe + " Bytes", "", "" + fileDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
// tableModel.fireTableDataChanged();
// tableModel.fireTableRowsInserted(0,1);
table.revalidate();
table.validate();
class MyTableModel extends DefaultTableModel
int totalRows;
int totalCols;
public MyTableModel()
super();
setColumnIdentifiers (columnNames);
this.totalRows = data.size();
this.totalCols = columnNames.length;
// this will return the row count of your table
public int getRowCount()
return totalRows;
// this return the column count of your table
public int getColumnCount()
return totalCols;
// this return the data for each cell in your table
public Object getValueAt(int row, int col)
MyObj obj = (MyObj)data.elementAt( row );
if( obj != null )
if( col == 0 ) return( obj.first );
else if( col == 1 ) return( obj.last );
else if( col == 2 ) return( obj.third );
else if( col == 3 ) return( obj.fourth );
else return( "" );
return "";
// if you want your table to be editable then return true
public boolean isCellEditable(int row, int col)
return false;
// if your table is editable edit the data vector here and
// call table.tableChanged(...)
public void setValueAt(Object value, int row, int col)
protected void deleteSelections (int rows)
try
removeRow(rows);
catch(ArrayIndexOutOfBoundsException e)
System.out.println("The error in the row index " + rows);
fireTableDataChanged() ;
class MyObj
String first;
String last;
String third;
String fourth;
public MyObj( String f, String l, String t, String fo )
this.first = f;
this.last = l;
this.third = t;
this.fourth = fo;
#####################################The following code works fine but it doesn't show me the new updated date in my JTable. I tried to print the values that I am getting and it does give the values on the prompt but doesn't show me on the JTable only first two are shown and the rest of the table is filled with the same values. I don't know what's going on and am tired of this TableModel thing so pla. take a time to give me some suggestions. Thanks
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class SimpleTable extends JPanel {
/** Formats the date */
protected SimpleDateFormat formatter;
/** two-dimensional array to hold the information for each column */
protected Object data[][];
/** variable to hold the date and time in a raw form for the directory*/
protected long dateDirectory;
/** holds the readable form converted date for the directories*/
protected String dirDate;
/** holds the readable form converted date for the files*/
protected String fileDate;
/** variable to hold the date and time in a raw form for the file*/
protected long dateFile;
/** holds the length of the file in bytes */
protected long totalLen;
/** convert the length to the wrapper class */
protected Long longe;
/** Vector to hold the sub directories */
protected Vector subDir;
/** holds the name of the selected directory */
protected String dirNameHold;
/** converting vector to an Array and store the values in this */
protected File directoryArray[];
/** hashtable to store the key-value pair */
protected static Hashtable hashTable = new Hashtable();
/** refer to the TableModel that is the default*/
protected DefaultTableModel model;
/** stores the path of the selected file */
protected static String fullPath;
/** stores the currently selected file */
protected static File selectedFilename;
/** stores the extension of the selected file */
protected static String extension;
protected Vector m = new Vector(0,1);
/** holds the names of the columns */
protected final String columnNames[] = {"Name", "Size", "Type", "Modified"};
public SimpleTable(File directoryArray[])
this.setLayout(new BorderLayout());
this.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
(SimpleTable.hashTable).clear();
data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
data[k][0] = directoryArray[k].getName();
data[k][2] = "File Folder";
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data[k][3] = dirDate;
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
else if(directoryArray[k].isFile())
data[k][0] = directoryArray[k].getName();
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data[k][1] = longe + " Bytes";
dateFile = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateFile));
data[k][3] = fileDate;
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
model = new DefaultTableModel();
model.addTableModelListener( new TableModelListener(){
public void tableChanged( javax.swing.event.TableModelEvent e )
System.out.println("************ I am inside the table changed method ********" );
final JTable table = new JTable(model);
table.getTableHeader().setReorderingAllowed(false);
table.setRowSelectionAllowed(false);
table.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
table.addMouseListener(new MouseAdapter()
/* public void mousePressed(MouseEvent e)
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
/* if(e.getClickCount() >= 2 &&
(table.getSelectedColumn() == 0) &&
((table.getColumnName(0)).equals(columnNames[0])))
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
upDateTable(table);
public void mouseReleased(MouseEvent e)
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
/* if(e.getClickCount() >= 2 &&
(table.getSelectedColumn() == 0) &&
((table.getColumnName(0)).equals(columnNames[0]))) */
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
upDateTable(table);
/** set the columns */
for(int c = 0; c < columnNames.length; c++)
model.addColumn(columnNames[c]);
/** set the rows */
for(int r = 0; r < data.length; r++)
model.addRow(data[r]);
DefaultTableCellRenderer D_headerRenderer = (DefaultTableCellRenderer ) table.getTableHeader().getDefaultRenderer();
table.getColumnModel().getColumn(0).setHeaderRenderer(D_headerRenderer );
((DefaultTableCellRenderer)D_headerRenderer).setToolTipText("File and Folder in the Current Folder");
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
this.add(scrollPane, BorderLayout.CENTER);
* Returns the number of columns
public int getColumnTotal()
return columnNames.length;
* Returns the number of rows
public int getRowTotal(Object directoryArray[])
return directoryArray.length;
private void upDateTable(JTable table)
if((table.getSelectedColumn() == 0) && ((table.getColumnName(0)).equals(columnNames[0])))
dirNameHold =(String) table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
File argument = findPath(dirNameHold);
if(argument.isFile())
CMRDialog.fileNameTextField.setText(argument.getName());
try
fullPath = argument.getCanonicalPath();
selectedFilename = argument.getCanonicalFile();
CMRDialog.filtersComboBox.removeAllItems();
extension = fullPath.substring(fullPath.lastIndexOf('.'));
CMRDialog.filtersComboBox.addItem("( " + extension + " )" + " File");
catch(IOException e)
System.out.println("THE ERROR IS " + e);
return;
else if(argument.isDirectory())
String path = argument.getName();
//find the system dependent file separator
//String fileSeparator = System.getProperty("file.separator");
CMRDialog.driveComboBox.addItem(" " + path);
subDir = Search.subDirs(argument);
/**TBD:- needs a method to convert the vector to an array and return the array */
directoryArray = new File[subDir.size()];
int indexCount = 0;
/** TBD:- This is inefficient way of converting a vector to an array */
Iterator e = subDir.iterator();
while( e.hasNext() )
directoryArray[indexCount] = (File)e.next();
indexCount++;
/** now calls this method and clears the previous data */
clearTableData(table);
(SimpleTable.hashTable).clear();
data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
m.clear();
data = null;
data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
System.out.println("Inside the if part");
data[k][0] = directoryArray[k].getName();
table.setValueAt(directoryArray[k].getName(),k,0);
//model.fireTableCellUpdated(k,0);
data[k][2] = "File Folder";
table.setValueAt("File Folder",k,2);
//model.fireTableCellUpdated(k,2);
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data[k][3] = dirDate;
table.setValueAt(dirDate,k,3);
//model.fireTableCellUpdated(k,3);
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
m.add(data);
model.addRow(m);
model.fireTableDataChanged();
else if(directoryArray[k].isFile())
System.out.println("******* Inside the else part *******");
data[k][0] = directoryArray[k].getName();
System.out.println("The Name is == " + data[k][0]);
table.setValueAt(directoryArray[k].getName(),k,0);
System.out.println("The table cell value of the name is == " + table.getValueAt(k,0));
//model.fireTableCellUpdated(k,0);
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data[k][1] = longe + " Bytes";
System.out.println("The length == " + data[k][1]);
table.setValueAt(longe + " Bytes",k,1);
System.out.println("The table cell value of the length is == " + table.getValueAt(k,1));
//model.fireTableCellUpdated(k,0);
dateFile = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateFile));
data[k][3] = fileDate;
System.out.println("The modified date == " + data[k][3]);
table.setValueAt(fileDate,k,3);
System.out.println("The table cell value of the name is == " + table.getValueAt(k,3));
//model.fireTableCellUpdated(k,0);
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]); }
m.add(data);
model.addRow(m);
model.fireTableDataChanged();
// model.fireTableDataChanged();
// model.fireTableRowsInserted(0,1);
table.revalidate();
table.validate();
else
* Searches the Hashtable and returns the path of the folder or the value.
public File findPath(String value)
return (File)((SimpleTable.hashTable).get(value));
* This clears the previous data in the JTable
public void clearTableData(JTable table)
for(int row = 0; row < table.getRowCount() ; row++)
for (int col = 0; col < table.getColumnCount() ; col++)
table.setValueAt(null, row , col);
model.fireTableStructureChanged();
### -
Deleting DataLocationGroups (with MDM Data Manager or MDM Java API)
I´ve a lot of DataLocationGroups which are results of tests (importing pictures into the images tables but not stored as BLOB). I can´t see that the underlying table is exposed within MDM Data Manager. So i tried to delete the useless nodes with the DeleteGroup command.
However this seems not to be supported by the API
com.sap.mdm.commands.CommandException: Deleting of data location groups is currently unsupported
at com.sap.mdm.group.commands.DeleteGroupCommand.execute(DeleteGroupCommand.java:91)
I´m using the new Java API with MDM 5.5SP6.
No chance to remove the nodes?Thanks for your answer. I would possibly open a service call to check if there is a hotfix available. Maybe you have some idea how i can check if the a Location is already existent? From experiments when importing with the MDM Data manager, it seems that a path is represented by a tree of HierLocationGroupNodes.
For example: I´ve imported from
cde271480MMPPpictures.jpg using the Data Manager. When using the RetrieveGroupTree Command, i can see that there are two nodes named cde271480 (Id: GN39) with child node named MMPP (Id: GN89).
Maybe i now want to use the API to import a picture from
cde271480 estlocation into the images table. To get a locationID usable for the setDataLocationId i had to compare the pathname of the picture with elements of the GroupTree from the root. If one element of the path is not existent in the tree, i have to create this new element and connect it to the parent. And i can then use the ID of the Leaf node for the DataLocationId. Is this correct?
Maybe you are looking for
-
I only sign in to iTunes' store about once a week or so. But during each of my last 3 attempts (on different days, several days apart) on my first attempt to enter my password and hit submit, I am immediately told that my Apple account has been lock
-
Can not open PDF Files-have windows 7 & downloaded Adobe 9.2
Can not open up any PDF files. I have a new computer with windows 7. Have dowloaded 9.2 adobe reader as well as air. It comes up as File Conversion with options of select the encoding that makes your document readable. Nothing I choose works & th
-
Newbie Help, Downloading Apps
I have a motorola V60i (GSM) and I was wondering how I could download java programs to the phone, and if there are currently available premade programs or if I have to make them myself? Thanks, Lyle Gordon
-
How can I delete one page in a 3-page document?
hi everybody! i have this document structure: http://www.adrive.com/public/d319adba81cf1dc6d60759bb52e5e7b9229aec2fa575fb8ae3c8d8710a54b 030.html in the regular case it produces a pdf with 3 pages. in a particular case i need to delete the third page
-
Login/password to SQL plus - 100% Totally newbie!
Dear users, I'm a 100% Totally newbie - please bear over with me and forgive that I couldn't find the answer to my question in the arhive although I'm sure somebody else has asked exactly this question. And please don't say RTFM etc, because there ar