Objective:
The primary table I loaded into MySql has 2.5 MM records: ID, Ticker,
Date, Price; and all works well. My need is to write a QUERY to export
outfile?) multiple text files. For example, I have 6 years worth of
data, and need to generate 1 file per day that contains all the Tickers
and Prices for that day. Furthermore, I need the text file name to be
the name of the date (e.g. April 4, 1998 with 1000 Tickers & Prices
would result in a file that was named "040498.txt" (either csv or tab
delimited).
Is this possible? If so, can someone please help me in this effort...the
alternative is not pretty.
Thanks in advance![color=blue]
>
> Trevor[/color]
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I've got a website with dynamic content, each page (subject) got an ID. On every page there can be a number of links. These are either links to internal other pages on that website or external links.
For the internal links the only thing I need is the ID and Title of that page. Those can be found in the Tbl_subjects. As for external links I need ID, Title and URL which can be found in the Tbl_ext_links.
I've got a table named Tbl_linkboxes with: - a Subject ID which means that this link belongs on this subject page. - Link ID which is either an ID from Tbl_subjects or Tbl_ext_links - External a boolean column to indicate if the Link ID refers to the Subject table or the External links table
There's basically 2 questions: 1) How to make this work? I've got a query below as feeble attempt 2) Should I really really really consider to use 2 columns for IDs and removing the External boolean. And simply setting one of those fields in the columns to >0 while the other is 0.
Okay, here's my attempt
PHP Code:
SELECT s.Sub_id, s.Link_id (l.external IS FALSE, (SELECT Title FROM Tbl_subjects), (SELECT Title,URL FROM Tbl_ext_links) FROM Tbl_subjects s WHERE s.Sub_id = <some id>
Not sure if I should work with IIF here to make it work or something else. I'm almost tempted to kick the boolean column overboard and introduce a JOINT on both columns then, one for external link ids and other for internal page ids.
Amazing how long one can stare at a query and not being able to get it right
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
From my query: (Please note the Where clause values will look odd to you, however they are not broken or wrong (its how the system reads it (odd I know)). The only issue I have is the subquery.
/*Schedule Summary*/ SET NOCOUNT ON
--Patient Appointments
DECLARE @Today DATETIME DECLARE @Tomorrow DATETIME SET @Today = '10/29/2007' SET @Tomorrow = dateadd(d, 1, '10/29/2007')
SELECT Date=convert(datetime,convert(char(12),Start,1)), convert(datetime,aps.Start) AS ResourceStart, convert(datetime,aps.Stop) AS ApptStop, ApptTime = datediff(minute, aps.Start, aps.Stop), df.Listname AS Resource, Facility= f.ListName, d.Listname AS DoctorName, --'Available / No Appt' AS Type, (SELECT dbo.sfnGetAllocsForSlot(aps.ApptSlotId) FROM ApptSlot aps JOIN Schedule s ON aps.ScheduleId = s.ScheduleId)AS TYPE, 'Available' AS 'Patient Name', 1 as ApptKind
FROM ApptSlot aps JOIN Schedule s ON aps.ScheduleId = s.ScheduleId JOIN DoctorFacility df ON s.DoctorResourceId = df.DoctorFacilityId JOIN DoctorFacility f ON aps.FacilityId = f.DoctorFacilityId JOIN DoctorFacility d ON s.DoctorResourceId = d.DoctorFacilityId LEFT JOIN Appointments a ON aps.apptid = a.appointmentsID
WHERE --Filter on resource ( ('7' IS NOT NULL AND df.DoctorFacilityId IN (7)) OR ('7' IS NULL) ) AND ( (NULL IS NOT NULL AND aps.FacilityId IN (NULL)) OR (NULL IS NULL) ) AND (Start >= @Today OR @Today IS NULL) AND (Start < @Tomorrow OR @Tomorrow IS NULL) AND ApptId IS NULL AND APS.ListOrder <> -1
My client came back and wanted me to add in a filter for Transaction Date from my Query (see full query below):
WHERE pm.Source = 1 AND t.Amount <> 0 AND --Filter on date range ( (pm.DateOfEntry >= ISNULL('06/01/2005', '1/1/1900') AND pm.DateOfEntry < DATEADD(d,1,ISNULL('09/04/2007','1/1/3000'))) )
The issue is how the following subquerys are calculating their values. I think I need to add in something now on if the pm.DateOfEntry is between Date1 and Date2. Would this be right and if so, can someone assist me on the syntax or at least give me a start on it ...?? It appears as if the subqueries are not respecting any date logic, only the id being passed into them.
Section of Code I need assistance with:
PatBalance = (SELECT SUM(pva.PatBalance) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId), InsBalance = (SELECT SUM(pva.InsBalance) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId), Charges = (SELECT SUM(pva.OrigInsAllocation + pva.OrigPatAllocation) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId), Payments = (SELECT SUM(pva.InsPayment + pva.PatPayment) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId), Adjustments = (SELECT SUM(pva.InsAdjustment + pva.PatAdjustment) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId)
/* Get the subset of visits for this report */ INSERT #Visit SELECT pv.PatientVisitId, pv.PatientProfileId FROM PatientVisit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitID = pva.PatientVisitID INNER JOIN PatientProfile pp ON pv.PatientProfileId = pp.PatientProfileId WHERE pp.PatientProfileId = 462 AND pva.PatPayment <> 0 AND --Filter on date type and range ( ('1' = '1' AND pv.Visit >= ISNULL(NULL,'1/1/1900') AND pv.Visit < dateadd(d, 1, ISNULL(NULL,'1/1/3000'))) OR ('1' = '2' AND pv.Entered >= ISNULL(NULL,'1/1/1900') AND pv.Entered < dateadd(d,1,ISNULL(NULL,'1/1/3000'))) ) AND --Filter on doctor ( (NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR (NULL IS NULL) ) AND --Filter on facility ( (NULL IS NOT NULL AND pv.FacilityID IN (NULL)) OR (NULL IS NULL) ) AND --Filter on company ( (NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR (NULL IS NULL) )
/* Get demographics for the patient */ INSERT #Ledger ( PatientProfileId, Type, PatientId, Birthdate, PatientName, PatientAddress1, PatientAddress2, PatientCity, PatientState, PatientZip, PatientPhone1, PatientPhone1Type, PatientPhone2, PatientPhone2Type, PatBalance, InsBalance, Charges, Payments, Adjustments )
SELECT DISTINCT pp.PatientProfileId, 1, pp.PatientId, pp.Birthdate, RTRIM(RTRIM(RTRIM(ISNULL(pp.First, '') + ' ' + ISNULL(pp.Middle, '')) + ' ' + pp.Last) + ' ' + ISNULL(pp.Suffix, '')) AS PatientName, pp.Address1, pp.Address2, pp.City, pp.State, pp.Zip, pp.Phone1, pp.Phone1Type, pp.Phone2, pp.Phone2Type, PatBalance = (SELECT SUM(pva.PatBalance) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId), InsBalance = (SELECT SUM(pva.InsBalance) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId), Charges = (SELECT SUM(pva.OrigInsAllocation + pva.OrigPatAllocation) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId),
Payments = (SELECT SUM(pva.InsPayment + pva.PatPayment) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId), Adjustments = (SELECT SUM(pva.InsAdjustment + pva.PatAdjustment) FROM #Visit pv INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId WHERE pv.PatientProfileId = pp.PatientProfileId) FROM PatientProfile pp INNER JOIN #Visit tv ON pp.PatientProfileId = tv.PatientProfileId /* Get visit information for the patient */ INSERT #Ledger (PatientProfileId, Type, PatientVisitId, VisitDateOfService, VisitDateOfEntry, DoctorId, DoctorName, FacilityId, FacilityName, CompanyId, CompanyName, TicketNumber ) SELECT pv.PatientProfileId, 2, pv.PatientVisitId, pv.Visit, pv.Entered, pv.DoctorId, d.ListName AS DoctorName, pv.FacilityId, f.ListName AS FacilityName, pv.CompanyId, c.ListName AS CompanyName, pv.TicketNumber FROM #Visit tv INNER JOIN PatientVisit pv ON tv.PatientVisitId = pv.PatientVisitId INNER JOIN DoctorFacility d ON pv.DoctorId = d.DoctorFacilityId INNER JOIN DoctorFacility f ON pv.FacilityId = f.DoctorFacilityId INNER JOIN DoctorFacility c ON pv.CompanyId = c.DoctorFacilityId /* Get diagnosis information for the patient's visits */ INSERT #Ledger ( PatientProfileId, Type, PatientVisitId, InternalCode, ExternalCode, Description ) SELECT pv.PatientProfileId, 3, pv.PatientVisitId, pvd.Code, pvd.ICD9Code, pvd.Description FROM #Visit tv INNER JOIN PatientVisit pv ON tv.PatientVisitId = pv.PatientVisitId INNER JOIN PatientVisitDiags pvd ON pv.PatientVisitId = pvd.PatientVisitId /* Get transaction information for the patient's visits */ INSERT #Ledger ( PatientProfileId, Type, PatientVisitId, PatientVisitProcsId, TransactionDateOfServiceFrom, TransactionDateOfEntry, Description, Payer, PatAmount, InsAmount, Action, Notes ) SELECT pv.PatientProfileId, 5, pv.PatientVisitId, NULL, ISNULL(pm.CheckDate, b.Entry), b.Entry, at.Description + CASE WHEN pm.CheckCardNumber IS NULL THEN '' ELSE ' - Check # ' + pm.CheckCardNumber + ' ' + CASE WHEN pm.CheckDate IS NULL THEN '' ELSE CONVERT(varchar(12), pm.CheckDate, 101) END END, pm.PayerName, CASE WHEN pm.Source = 1 THEN t.Amount END, CASE WHEN pm.Source = 2 THEN t.Amount END, t.Action, CASE WHEN ISNULL(t.ShowOnStatement, 0) <> 0 THEN t.Note ELSE NULL END FROM #Visit tv INNER JOIN PatientVisit pv ON tv.PatientVisitId = pv.PatientVisitId INNER JOIN VisitTransactions vt ON pv.PatientVisitId = vt.PatientVisitId INNER JOIN Transactions t ON vt.VisitTransactionsId = t.VisitTransactionsId AND t.Action = 'P' INNER JOIN PaymentMethod pm ON vt.PaymentMethodId = pm.PaymentMethodId AND ISNULL(pm.InsuranceTransfer, 0) = 0 INNER JOIN Batch b ON pm.BatchId = b.BatchId LEFT JOIN MedLists at ON t.ActionTypeMId = at.MedListsId WHERE pm.Source = 1 AND t.Amount <> 0 AND --Filter on date range ( (pm.DateOfEntry >= ISNULL('06/01/2005', '1/1/1900') AND pm.DateOfEntry < DATEADD(d,1,ISNULL('06/30/2005','1/1/3000'))) )
SELECT tl.* FROM #Ledger tl ORDER BY tl.PatientProfileId, tl.PatientVisitId, tl.PatientVisitProcsId, tl.Type
I have the following SQL Statement and I am trying to pass in a wildcard for the "Branch Parameter". The Branch Parameter is a numeric field. I need (Branch = %) wildcard to select all the records. Can someone tell me the proper syntax for this? SELECT EmployeeID, CountryCode, FName, LName, Branch, Title, Status, Required, Total, PercentageFROM dbo.vw_Compliance_Percentage_EmployeeWHERE (Branch = @branch)ORDER BY Branch I receive the message failed to convert parameter value from string to an int32
Hello everyone. I've attached a copy of my recently created stored procedure but now I want to expound on it by creating synatx within it that will allow me to create a 'weighting' type of scenario based on pre-determined weight/ranking classifications (example: a selection of skill '1' would grant the user 2 points toward their ranking, a selection of skill '2' might grant the user 4 pts., etc.) In the end, the users would be tallied and sorted based on the highest ranking (in pts) to the lowest. The business I'm in is that we develop a web site interface for recruiters and potential job seekers to post resumes, develop a career plan and rank their current work status against the open market. In short, does anyone out there know how I can implement a "ranking" type system into the syntax provided below? I've considered the CASE statement but was not clear on how it would work. Any suggestions would be great.
set nocount on select @jobcity = city, @jobposition = position_id, @jobrelocate = relocate_assist, @jobtravel = travel_id, @jobstate = state, @jobyears = position_yrs from t_job_order where job_id = @job_id
select @totcount = count(*) from t_job_vstat where job_id = @job_id
select @totcount = @totcount + 3
DECLARE Cand_Cursor CURSOR FOR
select candidate_id, key_skill_desc, strongest from t_cand_vstat, t_key_skill where t_cand_vstat.key_skill_id in (select key_skill_id from t_job_vstat where job_id = @job_id) and t_cand_vstat.key_skill_id = t_key_skill.key_skill_id order by candidate_id
CREATE TABLE #ReturnTemp ( candidateid uniqueidentifier NOT NULL, displayid int, city varchar(50), state varchar(2), Industry varchar(50), travel varchar(50), position varchar(50), hitcount smallint, tpercent numeric, ks1 varchar(50), ks2 varchar(50), ks3 varchar(50), ks4 varchar(50), ks5 varchar(50) )
OPEN Cand_Cursor
declare @candidate_id uniqueidentifier
FETCH NEXT FROM Cand_Cursor into @candidate_id, @key_skill_desc, @strongest select @holdid = @candidate_id
WHILE @@FETCH_STATUS = 0 BEGIN
if @candidate_id <> @holdid begin select @icount = @icount + 1 if @match = 1 update #ReturnTemp set hitcount = @icount, tpercent = (@icount/@totcount * 100), ks1 = @ks1, ks2 = @ks2, ks3 = @ks3, ks4 = @ks4, ks5 = @ks5 where candidateid = @holdid select @match = 1 select @ks1 = "" select @ks2 = "" select @ks3 = "" select @ks4 = "" select @ks5 = "" select @holdid = @candidate_id select @icount = 1 select @candrelocate = relocate, @candtravel = travel_id from t_cand_pref where candidate_id = @candidate_id select @candcity = city, @candstate = state, @displayid = display_id from t_candidate1 where candidate_id = @candidate_id select @candposition = position_id, @candyears = position_yrs, @candindustry = cat_sub_cat_id from t_cand_seek where candidate_id = @candidate_id if @candposition = @jobposition select @icount = @icount + 10 if @candyears = @jobyears select @icount = @icount + 8 if @candtravel = @jobtravel begin select @icount = @icount + 2 end
else if @jobtravel <> '91C858C8-4A46-4FD8-9B73-87FEE00F799E' begin if @candtravel = '91C858C8-4A46-4FD8-9B73-87FEE00F799E' begin select @match = 0 end else begin
select @icount = @icount + 1 end end
DECLARE City_Cursor CURSOR FOR
select distinct city, state from t_cand_pref_city_state C, t_city_state S where c.city_state = s.city_state and C.candidate_id = @candidate_id
OPEN City_Cursor
FETCH NEXT FROM City_Cursor into @prefcity, @prefstate
WHILE @@FETCH_STATUS = 0 BEGIN
FETCH NEXT FROM City_cursor into @prefcity, @prefstate select @citymatch = 0 if ((@prefcity = @jobcity) and (@prefstate = @jobstate)) begin --do nothing select @citymatch = 1 select @icount = @icount + 1 end
END
CLOSE City_Cursor
DEALLOCATE City_Cursor
if @citymatch = 0 select @match = 0
if @candindustry <> @jobindustry select @match = 0 if @strongest = 1 begin if @ks1 = "" select @ks1 = @key_skill_desc else if @ks2 = "" select @ks2 = @key_skill_desc else if @ks3 = "" select @ks3 = @key_skill_desc else if @ks4 = "" select @ks4 = @key_skill_desc else if @ks5 = "" select @ks5 = @key_skill_desc end if @match = 1 begin
select @candIndustrydesc = cat_sub_desc from t_cat_sub_cat where cat_sub_cat_id = @candIndustry select @candPositiondesc = position_desc from t_position where position_id = @candPosition select @candTraveldesc = travel_desc from t_travel where travel_id = @candtravel
INSERT INTO #ReturnTemp(Candidateid, displayid, city, state, Industry, travel, position, hitcount)
select * from linkboxes l left outer join subjects s on l.sub_link_id = s.sub_id left outer join external_links e on l.ext_link_id = e.ext_id where l.sub_id = subid
Hello, I am trying to update a table based on values that I have imported into a temporary table. Basically I have a list of lab codes (EMR_temp_labtest_configupdate) and each lab has a zseg code tied to it. The definitions for zseg code are in a separate table called (EMR_zseg_code_descriptions)
I need to update the lab_test_add_conf to add in each lab code that does not have any configuration information (not exists in lab_test_add_conf) based on the zsegcode.
For example a zsegcode (defined in the emr_zseg_code_descriptions table) is ZBL and the lab code 003277 fits into the zseg category according to the temp table. For each lab code that first into the ZBL category a row needs to be inserted for
I want to look at the data in the temp table and determine which category it is in and then insert into the lab_test_add_conf table a row for each lab test each zseg table value code that exists.
My Final Goal: lab_test_add_conf:
lab test code, valuecode 003277, PATRAC 003277, HERITG
I know I need to do an update statement but I am not sure how to set up the SET statement or if there is anythign that I need to take into consideration. Here is my code so far.....any thoughts?
select a.labtestcode from EMR_temp_labtest_configupdate a Where Not Exists (Select * From lab_test_add_conf b where a.labtestcode = b.labtest_key)
update table lab_test_add_conf
select a.labtestcode,b.zsegcode,b.valuecode,b.valuedesc,b.valuetype,b.units, b.tablename,b.fieldname from EMR_temp_labtest_configupdate a join emr_zseg_code_descriptions b on a.zsegcode = b.zsegcode
I am getting the following syntax error to my query below. This query is similar to many I currently use and I have not been able to track down the error. Can anyone spot the error?
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '='.
Msg 102, Level 15, State 1, Line 43
Incorrect syntax near 'data'.
Select
e.account_number,
epi.Provider_Role = [1],
epi.Provider_Role = [2],
epi.Provider_Role = [3],
epi.Provider_Role = [4],
epi.Provider_Role = [5],
epi.Provider_Role = ,
epi.Provider_Role = [7],
epi.Provider_Role = ,
epi.Provider_Role = [9],
epi.Provider_Role = [10],
epi.Provider_Role = [11]
from (SELECT e.account_number,
row_number() over (partition by epi.PROVIDER_ROLE order by e.account_number asc) as rownum,
e.medrec_no,
e.account_number,
Isnull(ltrim(rtrim(pt.patient_lname)) + ', ' ,'')
+
Isnull(ltrim(rtrim(pt.patient_fname)) + ' ' ,'')
+
Isnull(ltrim(rtrim(pt.patient_mname)) + ' ','')
+
Isnull(ltrim(rtrim(pt.patient_sname)), '')
AS SRM_PatientName,
CONVERT(int,pm.PatientAge),
left(e.admission_date,11) as Admit_Date,
left(e.episode_date,11) as Disch_Date,
(CASE WHEN DATEDIFF(DAY, e.admission_date,e.episode_date) = 0 Then 1
ELSE DATEDIFF(DAY, e.admission_date,e.episode_date) END) AS LOS,
pm.PrinOpPhys,
epi.PROVIDER_CODE,
epi.PROVIDER_ROLE,
pe.PERSON_NAME as physician_name
From srm.episodes e inner join
dbo.PtMstr pm on pm.accountnumber=e.account_number inner join
srm.ITEM_HEADER ih ON ih.ITEM_KEY = e.EPISODE_KEY INNER JOIN
srm.PATIENTS pt ON pt.PATIENT_KEY = ih.LOGICAL_PARENT_KEY inner join
srm.CDMAB_PROV_EPI epi on epi.episode_key=e.episode_key inner join
srm.providers p on p.provider_key = epi.provider_key inner join
srm.person_element pe on pe.item_key = p.provider_key
Where e.episode_date is not null and pm.AnyProc like '%4495%'
Hello, I have the following stored procedure and the following aspx page. I am trying to connect this aspx page to the stored procedure using the SqlDataSource. When the user enters a branch number in textbox1, the autonumber generated by the database is returned in textbox2. I am not quite sure what to do to get this to execute. Can someone provide me assistance? Will I need to use some vb.net code behind? Stored ProcedureCREATE PROCEDURE InsertNearMiss @Branch Int, @Identity int OUT ASINSERT INTO NearMiss (Branch)VALUES (@Branch) SET @Identity = SCOPE_IDENTITY() GO
I am working on two versions of an application, one of which will be awindows forms application (which will need to be redistributable) andthe other will be a web application.I have MS Visual Studio 2005 (along with the developer's edition of MSSQL Server), but not MS Access. I also have MySQL, PostgreSQL, Sun'sapplication server, Tomcat and Apache web server. I am working onWindows XP Pro, and have installed the .NET 3 SDK and all relevantrelated products I could find (e.g. 2 extensions packages for VisualStudio).I have one MS Access database, to which my users should have read onlyaccess. I have, and have used, a tool for importing MS Accessdatabases into MySQL. I expect that SQL Server has a similar utilityhidden somewhere (where I haven't yet looked, though I HAVE beenlooking - obviously in the wrong places). I have located a similarutility for importing MS Access databases into PostgreSQL. I have notyet decided which servers to use for the web version, but that isanother story, for which I may raise another thread in due course (butI welcome suggestions which may reduce the effort required givenrequired effort for the windows forms app).My problem is for the windows form aplication (intended for use by asingle family). I expect to use ADO.NET. The question is, should Iimport the Access database into MS SQL, and redistribute it, along withMS SQL Server Express (or is that necessary), or distribute it just asan Access database and use the jet engine to access it. A relatedquestion is, "Does ADO.NET support creating new databases for a givenengine?" Imagine a recipe database. It is easy enough to create a SQLscript that creates all the required tables, indices, foreign keys,&c., but can I submit that SQL script to an ADO.NET object, along witha file name, and have it create, e.g., an Access database with thesupplied name. Or do I have to create a database file with nothing init other than the schema?I have more questions, but they'll have to wait.ThanksTed
Has anyone successfully used cherry's oledb provider for MYSQL to create a linked server from MS SQLserver 2005 to a Linux red hat platform running MYSQL.
I can not get it to work.
I've created a UDL which tests fine. it looks like this
[oledb]
; Everything after this line is an OLE DB initstring
I have an internal Project Management and Scheduling app that I wrote internally for my company. It was written to use MySQL running on a Debian server, but I am going to move it to SQL Server 2000 and integrate it with our Accounting software. The part I am having trouble with is the user login portion. I previously used this:
PHP Code:
$sql = "SELECT * FROM users WHERE username = "$username" AND user_password = password("$password")";
Apparently the password() function is not available when accessing SQL Server via ODBC. Is there an equivalent function I could use isntead so the passwords arent plaintext in the database? I only have 15 people using the system so a blank pwd reset wouldn't be too much trouble.
Hi Folks, I have a slight problem designing two drop down lists accessing my database as some clients are listed twice because they are located in multiple citys I have one table called Clients with the following columns Client City F_name L_name ID I am using SELECT DISTINCT Client FROM Clients for my first Dropdownlist with a postback etc. e.g. Brown Black The Second Dropdownlist must select the different Distinct City Values where they are located on selecting Dropdownlist one e.g. Brown > London, New York or Black > Singapore and Boston What SQL Code can i place so the second dropdownlist will select the correct values on selecting the first Dropdownlist.
I need some explanantion on the following query that I'm trying to run:
if exists (select * from sysobjects where id = object_id ('slice_trace') and sysstat & 0xf = 3) delete from slice_trace where control_seq_number = 130 and claim_number = 7912450
When I run this query within a database where the slice_trace table does NOT exist, it still seems to execute the delete statement and hence fails because the object is not there. Essesntially I need this statement to execute only in databases where the table exists.
I new it was a mistake changing from mysql to mssql! I'm having difficulty with the following and would really appreciate any help you could offer.
I have two tables.
The first [users] has personal details: [id] [business_name] [title] [surname] [firstname]
The second [orders] has their orders: [order_id] [user_id] [order_date] [order_price]
I need a query that returns the latest record from [orders] for each member, with member details, but only where the latest order was within (now)-425.
I have received a table of data that has a field containing dateinformation. Unfortunately it was derived from a MainFrame dump andoriginated as a txt file and was then ported into an Access MDB filebefore it became an SQL table. The date format is vchar(50) andactually is comprised of 6 charecters ie: 010104 for Jan 1 2004. Ineed to run a select statement for a range of dates such as 010104thru 030104. Unfortunately being a charecter field this returnsincorrect results under a majority of cases. Back in my dBase daysthere was a VAL() that could be used in this case but I have beenunable to find anything comperable in SQL. Can anyone help me please?Thanks in advanceSteve
Error: "A connection was successfully established with the server, but an error occurred during the pre-login handshake. (provider: SSL Provider, error:0 - The certificate chain was issues by an authority that is not trusted.) (Microsoft SQL Server)
I am running SQL Server 2005 Developer ed. Windows XP SP2 Trying to connect over the internet to a SQL Server 2005 Workgroup ed. SP1 on Windows Small Business Server 2003 SP1 I have had success doing this before. I can terminal sevice in to the box and confirm my credentials work "Force Enycrption" has not been enabled on either the server or the client The Certificate tab is clear under "Protocols for MSSQLServer", but the server does have certs I can see them in the "Certificate" dropdown.
I have been working for some time on this T-SQL statement and getting it to work the way I would like it to work. I have been reading through books and everything, but am still having trouble. I am pretty new to T-SQL so I am probably making some beginners mistakes.
Basically I am working on a SQL 2005 server and I have a single database with two tables. Below are the tables and the fields that I am using from each. The table name is in bold and the fields are plain.
Users username (PK, varchar(7), not null) full_name (varchar(50), not null)
call_history queue (varchar(6), not null) update_date (datetime, null) status (char(1), not null)
Ok, now that you have the gist of the tables and fields. What I am trying to do is the impossible I think. Basically I work in a call center that supports software. The queue field is the identifier of what specialist is handling any call within the table. It can be linked to the "username" on the Users table. One thing I just noticed is that the varchar has a difference. Will that affect my below select statement?
SELECT u.full_name AS 'Specialist Name', COUNT (*) FROM dbo.call_history c LEFT OUTER JOIN dbo.users u ON c.queue = u.username WHERE (c.status = 'P') AND (DATEDIFF(dayofyear, update_date, getdate()) >= 6) AND (DATEDIFF(dayofyear, update_date, getdate()) <= 9) AND queue IN('alatif', 'AWILLI', 'AYOUNG', 'BPRING', 'CSKINN', 'DALDEN', 'DBACCH', 'DGIZZI', 'DKUSSA', 'DMCCUE', 'EKEPFE', 'GBACKH', 'GJONES', 'HESTAL', 'JBANKS', 'JCRICH', 'JDELGA', 'JFOLCH', 'JGRAVE', 'JHARRI', 'JLI', 'JMYERS', 'JPOPPE', 'JRICHA', 'JRIMME', 'JTHOMP', 'JWELLS', 'KDUKHI', 'KSTANL', 'LCHAMP', 'LGABOR', 'LHARVE', 'LMONTG', 'LSHORT', 'LTOM', 'MBECK', 'MJONES', 'MVANDE', 'NBROWN','NTOMPK', 'PELLIS', 'RATTAR', 'RDODGE', 'TANDRO', 'TBROWN', 'TDAVIS', 'TNDREX', 'TNORRI', 'YSOSA', 'YWILLI') GROUP BY full_name ORDER BY full_name
So here is my dilemma: I am trying to emulate a spreadsheet that was given to me by my boss. This is pretty much going to determine whether or not I can get a job as the Web Developer. So the spread sheet displays the number of calls that have not been updated in X amount of days for all of our reps. I have been trying so many different varieties from nested SELECT statements now to joins. To put it simply enough, do I need to do a query that populates column by column?
Here is what it should look like: http://i135.photobucket.com/albums/q129/tico1177/CropperCapture1.jpg
As you can see, I have to include everyone even if they have zero. That is where the problem comes in. When I use the above statement, the list shows up but takes away people from the list instead of keeping them and placing a null for the count. I have tried placing a HAVING statement at the bottom of the query to compensate for COUNT(*) = 0, but I get an error. I think because I have a WHERE statement.
I am trying to see if this whole thing can be done with a SQL statement to avoid having loop though in code. I basically want to populate a datagridview with the information that I gather.
I am trying to build a related article display. I have a SQLDataSource that I want to be able to select information (Category) from the table (Articles) based on a querystring (ID). SELECT [Category] FROM [Articles] WHERE ([ArticleID] = @ID) which for an example, lets say ID = 1, and it results as Category = Health.That is easy enough, but how would I then select all columns from the table WHERE Category = Result of first SELECT? SELECT * FROM [Articles] WHERE ([Category] = ??? Result of prior select) Can this be done in 1 select command, or would a store procedure need to be written? I am a little lost, sincr I am using a SQLDataSource, and it will be displayed with a Repeater. Thanks!
I'm using SQL 2000 and would like to send a generated email using this stored procedure: select Libraryrequest.LoanRequestID, Titles.Title, requestors.fname+ ' ' + requestors.lname as [Name], libraryrequest.requestdate,libraryrequest.shipdate,libraryrequest.duedatefrom libraryrequestjoin requestors on requestors.requestorid=libraryrequest.requestoridjoin Titles on Titles.Titleid = Libraryrequest.titleidwhere duedate < DATEADD(day, DATEDIFF(day, '20010101', CURRENT_TIMESTAMP), '20010101') I know I need to go to Management, SQL Server Agent, Jobs, New Job. Do I put the stored procedure in the descriptions part? After that I'm lost what do I do.
I need to write a query to provide MaxDate of each Exam and still show the ID of that Exam. My table is ID Exam Date 1 FMS 1/1/2006 2 FMS 1/1/2007 3 FMS 1/1/2008* 4 ECS 1/1/2006 5 ECS 1/1/2007 6 ECS 1/1/2008* My attempted query isSELECT ID, Exam, Max(Date) AS MaxOfDateFROM Table1 GROUP BY ID, Exam; My query actual results ID Exam Date 1 FMS 1/1/2006 2 FMS 1/1/2007 3 FMS 1/1/2008* 4 ECS 1/1/2006 5 ECS 1/1/2007 6 ECS 1/1/2008* My desired results ID Exam Date 3 ECS 1/1/2007 6 ECS 1/1/2007
I would appreciate any help that could be provided.
First off, here is my query:SELECT DeviationDist.DEVDN, DeviationDist.DEVDD, DEVDA, DEVCT, DEVST, DEVBG, DEVDV, DEVPS, DEVAT, DEVCN, DEVCF, DEVCP, DEVCEFROM DeviationDistINNER JOIN DeviationContact ON DeviationContact.DEVDN = DeviationDist.DEVDNWHERE DeviationDist.DEVDN = '200270'ORDER BY Deviationdist.DEVDN DESCI'm joining the deviationcontact table to the deviation dist table by DEVDN. This query works fine except when the DeviationContact table doesnt contain any records for the DEVDN that the DeviationDist table does contain. In my app, Deviationdist will always have an record for each DEVDN, but DeviationContact may not. I would like to still get the results back for what records exist in the DeviationDist table, even if DeviationContact has no associated records, but still show them if it does...
-- I want all sites even if they are not in the syslog table.
-- select count(gssites.sname) from gssites -- where gssites.rectype = 'S' = 67
-- this query returns 13 rows, I want all 67
declare @start int, @end int set @start = 1 set @end = 0 selectgssites.sname'SyncSite' ,syslog.resultcode'RES' ,rtrim(convert(varchar(2),datepart(month,SYSLOG.ON DATE)) +'-'+convert(varchar(2),datepart(day,SYSLOG.ONDATE )) +'-'+convert(varchar(4),datepart(year,SYSLOG.ONDATE)) )'SyncDate'
from Syslog left outer join gssites on gssites.sname = substring(syslog.siteid,9,8)
wheregssites.rectype = 'S' AND (SYSLOG.RECTYPE='G') AND (SYSLOG.ONDATE Between (GetDate()-@start) And GetDate()-@end) AND (SYSLOG.SITEID<>'') AND (SYSLOG.RESULTCODE='SUC')
I have a need to renumber or resequence the line numbers for each unique claim number. For background, one claim number many contain many line numbers. For each claim number, I need the sequence number to begin at 1 and then increment, until a new claim number is reached, at which point the sequence number goes back to 1. Here's an example of what I want the results to look like:
Hopefully this will be painless for you guys/gals - however due to my lack of skills/knowledge I need some clarification.
I have table_X which I have a trigger on INSERT setup. This trigger updates Field_2 = '1' and inserts some rows in another table.
Is there some way that I can restrict this trigger to only run when Field_1 = "BLAH" So essentially I am trying to find out how I can pull information/data from the record that fired the trigger and use this in the trigger? (ie to check if Field_1 = "BLAH" and to use Field_3 to further restrict the underlying triggers' updates and inserts)
Hopefully I have given enough information on this one - if not please let me know any points that I should need to clarify.
I realize this query is inherently incorrect, but my issue is mainly syntax. The line, "WHEN a.order_id <> b.order_id THEN" is wrong. I want to ensure that a.order_id is not in the settlement table. So I was thinking something along the lines of "WHEN a.order_id not in (select order_id from settlement)" which I know will cause a slower response time, but I'm willing to deal with it. In any case, that syntax doesn't appear to work.
sum( CASE WHEN a.ready_to_pay_flag = 'Y' and a.deduction_type = 'E' and ( CASE WHEN a.order_id <> b.order_id THEN a.transaction_date ELSE b.delivery_date END) used_date datediff(d,used_date, ".$cutOffDate.") < 30) THEN a.amount END) earn_amount_rtp_curr,
I have a trigger that I created to log changes in one table to anothertable but it is horribly inefficient.I am hoping that someone with more experience than I can see a way tomake this trigger more efficient.------------ALTER TRIGGER tContacts_ChangeLogON dbo.ContactsFOR UPDATEASSET NOCOUNT ONDECLARE @tablename varchar(20),@record_id_column varchar(30),@colname varchar(30),@colvalue varchar(8000),@insertstmt varchar(1500),@username varchar(20)SELECT @tablename = 'Contacts'SELECT @record_id_column = 'ContactID'DECLARE columns_cursor CURSOR LOCAL FORSELECT COLUMN_NAMEFROMINFORMATION_SCHEMA.COLUMNSWHERETABLE_NAME = @tablenameAND (POWER(2, (ORDINAL_POSITION-1) % 8) & CONVERT(INT,SUBSTRING(COLUMNS_UPDATED(), (ORDINAL_POSITION-1)/8 + 1, 1))) <> 0SELECT * INTO #del FROM deletedSELECT * INTO #ins FROM insertedSELECT @username = RIGHT(SYSTEM_USER, LEN(SYSTEM_USER) -CHARINDEX('',SYSTEM_USER))OPEN columns_cursorFETCH NEXT FROM columns_cursor INTO @colnameWHILE @@FETCH_STATUS = 0BEGINSELECT @insertstmt = 'INSERT INTO ' + @tablename + '_ChangeLog (recordid, fieldname, changedfrom, changedto, username, datetime ) ' +'SELECT d.' + @record_id_column + ', ''' + @colname + ''', d.' +@colname + ', i.' + @colname + ', ''' + @username + ''', GETDATE()' +'FROM #del d INNER JOIN #ins i ON d.' + @record_id_column + ' = i.' +@record_id_column + ' WHERE (i.' + @colname + ' <> d.' + @colname + ')'+' OR (i.' + @colname + ' IS NOT NULL AND ' + 'd.' + @colname + ' ISNULL) OR (i.' + @colname + ' IS NULL AND ' + 'd.' + @colname + ' IS NOTNULL)'-- INSERT INTO Debug (value) VALUES( @insertstmt )EXEC( @insertstmt )FETCH NEXT FROM columns_cursor INTO @colnameENDCLOSE columns_cursorDEALLOCATE columns_cursor
I am trying to pull some "notes" from a sql database.....the notes thatare put into the database come via the web and the user is entering itfor a certain task. they are stored in their own table and field andget assigned and incremental ID #.I want to be able to pull up the latest entry to the task, not all ofthe notes just the latest one.. The entry does get a timestamp in thefield so I am thinking I might be able to look at that fieldsomehow.... Right now my query shows all notes / entries for the task.I am an intermediate sql query guy so I hopefully expained enough toget assistance.Let me know if you need to know more.
I have a SQLAgent job created using isqlw to run the query and output the results to a file on the C drive. However, the job never completes, which is strange since the database is fairly new and when I run the query manually in a isqlw window, it completes and outputs the file in seconds.
I am trying to get a running total. I need the query to reset the running total for each year/id. Below is the sample query. Any help would be greatly appreciated.
SELECT v.k1, v.date, v.groupByThis, v.c1, RunningTotal=SUM(a.c1) FROM ( SELECT k1, date, groupByThis, c1, RANK() OVER (PARTITION BY k1 ORDER BY groupbythis, date) as Rank FROM #valueset ) v
CROSS JOIN
( SELECT k1, date, groupByThis, c1, RANK() OVER (PARTITION BY k1 ORDER BY groupbythis, date) as Rank FROM #valueset ) a WHERE a.Rank <= v.Rank AND a.groupByThis = v.groupByThis GROUP BY v.k1, v.date, v.groupByThis, v.c1 ORDER BY v.groupByThis, v.date