Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all 13329 articles
Browse latest View live

Unique Records Insert

$
0
0
Any help appreciated.

I'm creating a helpdesk solution where i am extracting emails through Vb.net service from MS Exchange into SQL using Exchange API. The following query works fine and in SQL Server 2012, i have the MessageID column set to unique, indexed and ignore duplicate keys set to yes.

cmd.CommandText = "INSERT INTO Tickets ([Oid], [MessageID]) VALUES (@GuidValue, LEFT('" & E_ID & "', 255))"

The service grabs the most recent 10 emails and pops them into SQL


i've created a trigger on the table Tickets to insert a value of 1 in a column called InsertFlag for new records inserted through the service

Issue
the windows service obtains the 10 most recent emails every 10 minutes and inserts them in an SQL Table called Tickets
let's say on the next windows service run, there are only 2 new emails
the trigger still seems to update the other 8 existing records also

Trigger

USE Helpdesk
GO
CREATE TRIGGER InsertFlagTrigger
ON dbo.Tickets
AFTER INSERT
AS
DECLARE @insertflag int
Set @insertflag = '1'
BEGIN
update Tickets
set InsertedFlag = @insertflag
END
GO


Is it the Trigger causing the issue or is SQL ignoring duplicate keys set to yes and still updating the 10 records if only 2 new records are new ?

Many thanks

[SQL Server 2008] Problem with Between syntax

$
0
0
[SQL Server 2008] Problem with Between syntax

Hi there, hope in your help.

In SQL server I have the column doTableDate set a Datetime.

I need extract all rows in on date range and I think use to syntax `Between And`

If try this version of query I have in output 889 rows all with date 2014-01-03... but I have other records with date 2014-01-04 in column doTableData...

Code:

SELECT
        *
FROM
        doTable
WHERE
        doTableDate BETWEEN CONVERT (
                datetime,
                '03/01/2014 00:00:00',
                103
        )
AND CONVERT (
        datetime,
        '04/01/2014 00:00:00',
        103
);

If try this version I don't have output no record, why?
The syntax `Between And` not working in SQL Server?

Can you help me?
Thank you in advance.

Code:

SELECT
        *
FROM
        doTable
WHERE
        doTableDate BETWEEN CONVERT (
                datetime,
                '03/01/2014 00:00:00',
                103
        )
AND CONVERT (
        datetime,
        '03/01/2014 00:00:00',
        103
);

Query criteria question !

$
0
0
Hello everyone,

I have a question. I'm looking to find out whether there is a type of criteria i can put in my query that allows which forbids one record to have the same values as the following record (i.e duplicate).

Any help is appreciated !

Assess synonym through linked server

$
0
0
Hello All,
I am trying to write a stored procedure on my server (A) to query data from a remote server (B). I have created a linked server to the remote server. The remote server also has a linked server to another server (C). Synonyms are created on server B. My task is to query these synonyms. Is this possible? I wrote the following but it's throwing an error;

create procedure pr_test
as
select top 1 * from STAR.LIFE.dbo.websvr_view_beneficiaries

where STAR is the linked server on my server (A), LIFE is the database name on server B and websvr_view_beneficiaries is the synonym on server B

The error I get is "The OLE DB provider "SQLNCLI11" for linked server "STAR" does not contain the table ""LIFE"."dbo"."websvr_view_beneficiaries"". The table either does not exist or the current user does not have permissions on that table."

Any help will be appreciated

Restoring from HADR

$
0
0
Firstly I am using 9.7.9a in Linux 6.

We are going to run a load simulation test in prod and need to plan in the event of a rollback. Right now the plan is to run a backup before the test start on the primary db and turn off the secondary db. If there are no issues we just restart the secondary db and let the logs apply. But if we need to rollback we were looking at either restoring the primary using the backup OR take a backup of the secondary db and use this to restore the primary. The issue with the later is that we wouldn't want the secondary db to have logs applied from the primary db once we db2start the secondary.

My question is are there any gotchas I need to plan for when restoring an HADR? Can I just restore the primary and db2start the secondary db server and I'm done? or do I need to restore both servers using my backup file from the Primary? Can I use the secondary server as a backup db?

thanks,

James

not able to connect the db as sysdba

$
0
0
Hi,

few days ago i was able to login as sysdba now i am not able to connect to the db as a sysdba. Please advise...

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
PL/SQL Release 12.1.0.2.0 - Production
"CORE 12.1.0.2.0 Production"
TNS for Linux: Version 12.1.0.2.0 - Production
NLSRTL Version 12.1.0.2.0 - Production

$sqlplus / as sysdba

ERROR:
ORA-01017: invalid username/password; logon denied

Enter user-name: sys/pass@testdb as sysdba

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>

Trying to make a report off all tables, indices, constraints, keys, and such

$
0
0
We are mapping out a large database that has NO documentation.

And thus we are making our own.

I know I can use a SELECT * FROM pg_database or SELECT * FROM information_schema.columns WHERE table_name ='table';

But how does one recurse so one can go down the whole database and get every table (and if possible information of forms, reports, queries, and modules.)

Thanks!

Deaf

Excel corruption of .csv file data

$
0
0
I've become aware of the limitations of opening .csv data files into

Excel 2007 (earlier versions have the same issue). Various changes are

made to the data as the file is opened, including at least the

following:
* Fields that appear to be numeric and have leading or trailing zeroes

have the leading/trailing zeroes removed
* Values that Excel thinks match a date such as 5-10 get assigned a

data type of date. Reformatting the field's data type to text gives a

crazy value such as 40308 (probably the number of days from 1/1/1970 to

the date 5/10 in the current year)

Saving changes to the original .csv file causes permanent data loss as

the above changes are saved back to the file (What were they

thinking?!).

This issue can be worked around by using the Data -> Get External Data

From Text tool, but I deal with .csv files so frequently that I want an

easier way of getting my data opened without corruption. I came up with

the below set of actions:

When right clicking on a .csv file in Windows Explorer, a context menu

appears with various options. It would be useful to have an option

“Open without corruption using Excel” or similar, which does the

following:

1. Opens Excel
2. Creates a blank spreadsheet
3. Imports the select .csv file similar to the following commands:
a. Select Data -> From Text
b. Select the .csv file to be imported
c. Choose the “Delimited” option
d. Use comma as the delimiter character
e. Select all columns (hold shift and click the right-most

column header)
f. Change the “Column data format” to Text
g. Click Finish
h. Put the data into cell A1
4. And possibly even alter the currently open Excel file name from

“Book1” (or whatever it is) to the name of the .csv file that was

opened.

I have a colleague trying to learn to program with .NET that can

attempt this, but the key questions are:

1. Will it be possible to perform the above actions with .NET?
2. What is a general programming plan (perhaps which modules to use,

etc?) that I can pass on to my colleague for development?

Santander is hiring a Senior Manager - Enterprise-wide Customer Relationship Manageme

$
0
0
Enterprise-wide Customer Relationship Management (ECRM) is a major programme which will provide the ability to “intelligently” manage leads during customer contact, initially in our branches and ultimately also in Telephony and outbound channels. Initially, ECRM will improve the customer information available through reactive channels and provide targeted opportunities appropriate to each customer. Ultimately, it will improve both reactive and proactive contact with customers across the bank.

At the core of ECRM is a centralised decisioning process that will ultimately hold and execute the complex array of business rules and logic that will ensure that the right information and options are served to support each customer contact.

The Senior Manager of ECRM decisioning has principal responsibility for maintaining the operation of the centralised decisioning process, including performance monitoring, analysis, optimisation, rules configuration, compliance and control mechanisms.
As a Senior Manager (ECRM) your main responsibilities will involve:

Driving continual performance improvement of Santander’s centralised decisioning processes

Managing and maintaining business as usual operation of the ECRM capability in terms of customer opportunities, business rules and performance monitoring, including compliance and QA

Analysing and reporting on all aspects of ECRM performance, e.g. financial, transactional, interactional, content and operational

Maintaining an agreed roadmap of enhancements and/or extensions of the capability to improve business performance

Working proactively across the business to improve awareness, understanding and utilisation of the capabilities

Managing a team that typically includes insight and rules analysts, and capability and engagement specialists

Successfully driving business performance improvement from interpretation of operational and analytical insight for large B2C organisations

Working with delivery of sophisticated data intelligence at the point of customer interaction and through outbound channels

Driving the implementation and management of analytical and operational capabilities for data exploitation and commercialisation


What we will be looking for in you:

Higher level qualification (degree or post-grad) in numerate subject/equivalent

Exceptional statistical marketing analysis and data manipulation skills using tools such as SAS (EG/EM), SQL and Excel (advanced user)

Expert knowledge of database marketing principles, capabilities and opportunities

Practical knowledge of branch and/or call centre operations

Team player and self-starter

Excellent project planning and process management skills

Rewarding you

There are many advantages to being part of our family. We’ve got a reward package that’s simple, personal and fair. In addition to your pay and bonus, we offer you a benefits package that’s flexible and allows you to be in control, as well as all the policies, tools and guidance to support you working for Santander.

For your commitment and success, we offer one of the most competitive basic salaries with a distinct career development opportunity. Other Santander benefits include:

Annual car allowance of £6,000

Discretionary annual bonus

Private Medical Insurance

Pension

30 days Holiday plus bank holidays with the option to buy and sell 5

Product discounts

Retail and High Street discounts

Sharesave Scheme

Flex benefits including childcare vouchers

Location: Leicester

Why Santander?

With over 150 years of experience, we’ve built a strong, international presence, with more branches worldwide than any other bank. Dedicated to making things simple, personal and fair for our customers our aim is to become the best bank in the UK, and we know we can’t make it happen without our people. That’s why we promote an environment where everyone counts. With us, you’ll be encouraged to develop both professionally and personally, and by listening to your unique perspective, and turning your ideas into action, we’ll grow along with you.

We are committed to helping you achieve a reasonable balance between your home and working life. To support you in meeting your commitments outside of work, we offer a range of flexible work options, including part-time working, job sharing, career breaks and flexible holiday options and we support you to make a difference in your local community with volunteering and fundraising schemes.

If you’re interested in this role, please apply on the link below and our recruitment team will be in contact shortly.

Santander welcomes applications from all sections of the community.

Apply here: https://express.candarine.com/campai...d/01e66c6b49d5

convert millisecond timestamp and then sort by date

$
0
0
I have a set of data with epoch timestamps. Purely for the sake of reporting, I need to pull the last six months of data and group it by month. I have tried searching the googles for epoch/milliseconds to datetime but I only get the MySQL or Oracle results, not MSSQL. And yes, I have been to the MSDN. I don't understand their examples. Would someone be willing to assist me with this?

Cannot open mdf file in Microsoft SQL Server Management Studio Express 2005

$
0
0
I had Microsoft SQL Server Express 2005 installed already. I just

installed the Microsoft SQL Server Management Studio Express 2005 and

tried to open my mdf file. I get an error message that says:

There is no editor available for 'C:\Inetpub\wwwroot\intranet\app_data

\intranet.mdf).
Make sure the application for the file type (.mdf) is installed.

Did I do something wrong? I just clicked through the defaults in the

Management Studio Express install.

How can I get this to work?

ROWID working for DB2 LUW 9.7.9a

$
0
0
I was surprised that this works. I thought ROWID was only available in z/OS, iseries.

I was curious if anyone uses rowid for updates, deletes?

try this:
select rowid, name from sysibm.systables

Exclude when the current month EXCEPT when?

$
0
0
Does anyone know how to INCLUDE the month of May or June data when the current month is May and if the current month is June but all other months exclude the "current" month?

I'm working with
Code:

  <>Month(Date())
to exclude current month, however I need ALL months when the current month is May or current month is June. Meaning only in the month of May or month of June I need the <>Month(Date()) to NOT take affect.

Code:

<>Month(Date()) and (Month(Date()) Not In (5,6))
does not work, it results in Null
Code:

<>Month(Date()) and (Month(Date()) In (5,6))
does not work, it also results in Null

There has to be a way to do this, anyone know the correct formula?

Duplicated Values in Query from two tables using Iif Function

$
0
0
Hi everyone!

Really need some help here.

I tried to make a query where it forms a new field. The new field is suppose to retrieve the export rate value from the ExchangeRate Table IF the date of the Lifting falls between the dates in the Exchange Rate (because the exchange rate is valid for a certain period of time).

I had an ALMOST successful attempt because it worked but I got multiple duplicated values (see image).

Query.png

My tables that are involved in the query are as below:

ExchangeRateTable.pngLiftingTable.png

For your reference, my SQL is as below:

SELECT DISTINCT Lifting.*, IIf([Lifting]![Lifting Date End] Between [ExchangeRate]![StartDate] And [ExchangeRate]![EndDate],[ExchangeRate]![Export Rate],IIf([Lifting]![Lifting Date End]>[ExchangeRate]![EndDate],"RATE UNAVAILABLE","NULL")) AS ExchangeR
FROM ExchangeRate, Lifting;

Can someone let me know where I've gone wrong or anything I missed?

Thank you in advance! Any ideas / suggestions to go about this is HIGHLY appreciated!

Best regards
Attached Images

modification of vba looping through unique values, saving them into new workbooks

$
0
0
Hello,
I’m a new to VBA and found a macro which does almost what I want but need to be modified. I’ d be very grateful if you could help.
Let’s say I have:
- a workbook called “Source.xlsm” with 30 unique values in col A and 50 other columns fulfilled. First row is filled with column names
ID Name1 Name2 Name…n
A00001 A1 A2 A…n
B00002 B1 B2 B…n
……

- a workbook called “Dest.xlsm”; formatted file to which I want to copy unique values + all of the columns from “Source.xlsm”


A00001
A1
A2
A…n

- where in cell “D3” should be value from “Source.xlsm” A2. A1,A2, An…. should be below cell “D3”

I need a macro which will:
- open a “Source.xlsm”
- open “Dest.xlsm”
- loop through all of unique values in col A of “Source.xlsm”
- copy each of unique value to the separate “Dest.xlsm” file where in cell “D3” should be value from “Source.xlsm” A2. A1,A2, A…n should be below cell “D3”
- save the separate files “Dest.xlsm” for each of the unique value from col. A naming for example “A00001_ddmmyyyy.xlsm” where dd-day, mm-month, yyyy-year
- close all files

Macro, which loops through unique values in col A and simply copies these values into separate workbooks instead of copying them into separate “Dest.xlsm” for each of the unique value from col. A



Sub Extract_All_Data_To_New_Workbook()

'this macro assumes that your first row of data is a header row.
'will copy all filtered rows from one worksheet, to another blank workbook
'each unique filtered value will be copied to it's own workbook

'Variables used by the macro
Dim wbDest As Workbook
Dim rngFilter As Range, rngUniques As Range
Dim cell As Range


' Set the filter range (from A1 to the last used cell in column A)
'(Note: you can change this to meet your requirements)
Set rngFilter = Range("A1", Range("A" & Rows.Count).End(xlUp))

Application.ScreenUpdating = False

With rngFilter

' Filter column A to show only one of each item (uniques) in column A
.AdvancedFilter Action:=xlFilterInPlace, Unique:=True

' Set a variable to the Unique values
Set rngUniques = Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisi ble)

' Clear any filter

On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0


End With

' Filter, Copy, and Paste each unique to its own new workbook
For Each cell In rngUniques

' Create a new workbook for each unique value
Set wbDest = Workbooks.Add(xlWBATWorksheet)

'NOTE - this filter is on column A (field:=1), to change
'to a different column you need to change the field number
rngFilter.AutoFilter Field:=1, Criteria1:=cell.Value

' Copy and paste the filtered data to its new workbook
rngFilter.EntireRow.Copy
With wbDest.Sheets(1).Range("A1")
.PasteSpecial xlPasteColumnWidths 'Paste column widths
.PasteSpecial xlPasteValuesAndNumberFormats 'Paste values
End With
Application.CutCopyMode = True

' Name the destination sheet
wbDest.Sheets(1).Name = cell.Value

'Save the destination workbook and close
wbDest.SaveAs ThisWorkbook.path & Application.PathSeparator & _
cell.Value & " " & Format(Date, "mmm_dd_yyyy")
wbDest.Close False 'Close the new workbook

Next cell

rngFilter.Parent.AutoFilterMode = False
Application.ScreenUpdating = True


End Sub


regards,
s

Identifying Functional Dependencies

$
0
0
If i have a table with the headings

Organisation Country of Origin Software Name Software type Version

What would the functional dependencies be? The primary key is a composite key with organisation and software name

Need help with assignment to create ERD solution

$
0
0
A software development company requires a database to record details about its
projects. Each project has its own project number, name, project leader and
employees assigned to it. Each employee has an employee number, name and
job classification.
The company charges its clients by billing the hours spent on each project by its
employees. The hourly billing rate is dependent upon the employee’s position
(job classification). For example, one hour of a database designer’s time is billed
at a different rate than one hour of a programmer’s time.
The first step is to examine the data provided in the spreadsheet below, which
contains the relevant information.


I have attached the table:
t.jpg

The following business rules apply:
 The company manages many projects.
 Each project requires the services of many employees.
 An employee may be assigned to several different projects.
 Each employee has a single primary job classification. This job classification
determines the hourly billing rate.
 Many employees can have the same job classification. For example, the
company employs more than one database designer.


TASK
1. Using the provided spreadsheet data and business rules you are to create a
fully expanded ERD solution for the system.

2. Convert the ERD solution from the previous question to a Relational Schema
indicating all primary and foreign keys. Note: Where appropriate break
attributes down further.

3. Construct a data dictionary for the tables.

4. Implement your design in MySQL. All tables must enforce referential
integrity where necessary (save your SQL statements in a script file called
Database2YourName(s).SQL).
Attached Images

Populating a DB from a remote source

$
0
0
Hi all, I’m a complete learner here with any type of database so unsure what phrases I need to search for here to get returned the correct results for my question.


I’m looking for a way to grab external data and populate a database on another site, for example if you look at the below link, I want to grab all the players name only and pop them into a database on another website, I understand that I could just manually input the names; but names could be added at any time to the site so I’m looking at an automated way of doing it.

Thank you for your time and I hope you can help me out.

http://full-time.thefa.com/DisplayTe...amID=757319359

impprove performance of "Insert into Select from.." query in sybase

$
0
0
Hi,
I am a java developer with not much experience on db stored proc programming. I just wanted to know if "INSERT INTO(a,b) SELECT a,b FROM.." kind of sqls locks source table also for the time of execution, in sybase.
I am using one such sql where it insets huge data (may be 200-300k) in temp table for further processing. And it seems affecting other processes running in parallel.
Can we ensure in someway that "INSERT INTO(a,b) SELECT a,b FROM.." doesn't lock the source table...
Any help would be greatly appreciated. Thank you..

set variable and calculate % change between different lines

$
0
0
hi everybody,i'm new here and in mysql world...trying to learn something new everyday. I'm working on a bi platform based on mysql reports and i have a problem with one of them.

I want the report to tell me sales of a shop by year and month and i want to calculate the change between sales of the months. For example

shop year month sales diff
142 2015 may 11.000 +10%
142 2015 abr 10.000 ....

I tried to set a variable (@prev_val) but when i execute the query it gives an error.

If somebody could help me...

Thanks in advance:rolleyes:




set @prev_val=0;

SELECT
d1.ID_shop,
year(d1.Date),
month(d1.date),
sum(d1.salesl),
sum(d1.sales)-@prev_val ,
@prev_val:=sum(d1.sales)
FROM
dati_giornalieri d1
WHERE
year(d1.date)=2015 and
d1.id_shop=142
group by
month(d1.date)
Viewing all 13329 articles
Browse latest View live