I'm a bit new to MS-SQL so i thought maybe you could help me.
This is my prob. I have an Access application that i have upsized to a MS-SQL server. I have a query based on 3 tables: Customers, Companys and Payreminders. When i run this query, i can't add new records or make any changes.
If i only run the query with the tables: companys and payreminders i can add new records and edit them. If i run a query that's based on companys and customers, i can edit and add new records, but when i run the query based on companys and customers i can't add or edit records.
companys, payreminders: Editable
payreminders, companys: Editable
Companys, customers: Non editable
Companys, payreminders, customers: Non editable
Something must go wrong when i use the companys and customers table. Can anybody help or give a suggestion what to do.
Sorry for the less then descriptive post title but I didn't find a better way to describe it. I'm developing an app in the express editions of VB and SQLserver. The application is a task/resource scheduler. The main form will have a datepicker or weekly overview and show all tasks scheduled per day. The problem is, I've got one or more people assigned to tasks and I wonder what's the best way to design this. Personally, I'd go for one Task table, a People table and a table that provides a link between them (several record per task, one for each person assigned linking TaskID and PplID). However, I don't see a nice way of showing this data to the end user, allowing him to edit/add etc on ONE screen.
To fix that the only way I see is just add columns to the Task table for every person with select boxes. This way everything can be done on one simple screen. This obviously does present some future issues.
On top of this, which people are available on a day varies and there should be an option to allow a user to set who is available on a specific day. Which would lead me to my first idea and add another table that would provide this. but then I'm having design issues again for the form.
I'm kinda stuck atm, can anyone shed some light on this. I'm sure there is an elegant way of doing this but I'm failing at finding it.
I have an SSIS package (SQL Server 2005) that gathers statistics (ie total records created, items created, items shipped, etc). I have made a UNION query to get the data (because it has to look at different date fields) that returns the following results: ID QTY Created 20 Shipped 30 Received 35
What I what to do is store this data as 1 record like this: Date Qty_Created Qty_Shipped Qty_Received 11/20/2007 20 30 35
I have a table of magazine issues. The table are defined as below:
issueID int Unchecked name varchar(50) Unchecked title varchar(100) Checked description varchar(500) Checked crntIssue bit Checked archived bit Checked navOrder int Checked dateCreate datetime Checked
And here is what I want. Is there a way when inserting/updating or on the table itself to make sure that there is only one record that is marked as the current issue? The way I have it here in my table, any records can have the current issue (crntIssue) field checked. I only want one crntIssue field checked regardless of how many records or issues are in the table. If there is no way to automatically have SQL Server to manage that then that means I must check all the records before hand before the update/insert query, correct?
I have a table of magazine issues. The table are defined as below: issueID int Uncheckedname varchar(50) Uncheckedtitle varchar(100) Checkeddescription varchar(500) CheckedcrntIssue bit Checkedarchived bit CheckednavOrder int CheckeddateCreate datetime Checked And here is what I want. Is there a way when inserting/updating or on the table itself to make sure that there is only one record that is marked as the current issue? The way I have it here in my table, any records can have the current issue (crntIssue) field checked. I only want one crntIssue field checked regardless of how many records or issues are in the table. If there is no way to automatically have SQL Server to manage that then that means I must check all the records before hand before the update/insert query, correct?
HI if I have a recrod in a plain text file , and it has some colums information including FromDate and ThruDates if the date range is over 30 days, Then the record should split and becomes 2 records rather then one.
for example: if i have MemberID=255 FromDate 07/01/06 and ThruDate = 08/25/06
than that single record should be saved as two records
Well the file is a fixed length file. On a web page. Page is uploaded. when the fixed length file is uploaded it converted into the xml file. After the xml file goes through the validation, it gets ready for the database. Each field in the fixed length file was a xml node and sent to the database.
Now what I have to check from the sqlManagement studio. Insert a query with the test query as I decribed earlier, and instead of it get to the database it should be splited into two record instead of one and get in the database table. And if dates are in between 30 days, then the recrod go into table with out any other issue.
I have a table where I need to set some rows to Read only (to protect the rows from being edited). Can I do this with a trigger checking against a column (where dataReadOnly = 1)?
Hello...i have a table that record all the reading meter....so when i change one of the reader meter data...in logical it will automatically change the normalized fields...
Reading teble ------------------- -id[PK] -meter -normalized -date when i insert new record..i just insert data about date and meter...an normalized is automated calculate using my function..the problem is..when i have data more than one...when i try insert or update or delete data...it nee to be automatically calculate back the normalized..i know this is needed the temperory table and then reinsert back..how can i solve this problem???
I have a table full of items that have a "date_updated" field. I'd like this field to be set to GETDATE() whenever a record is updated. I've got this trigger:
CREATE trigger tr_cp_shiptos_u on dbo.cp_shiptos for update as update cp_shiptos set date_updated = GETDATE()
Problem is, of course, there's no WHERE clause..yet. I don't know how to refer to the record that was updated.... for example:
CREATE trigger tr_cp_shiptos_u on dbo.cp_shiptos for update as update cp_shiptos set date_updated = GETDATE() where shipto_id = @THIS_ID
I imagine there's some kind of builtin variable or something like that. How is this done?
Approximately once a month, a client of ours sends us a bunch ofcomma-delimited text files which I have to clean up and then importinto their MS SQL database. All last week, I was using a Cold Fusionscript to upload the cleaned up files and then import the records theycontained into the database, though obviously, the process tookfriggin' forever, and could have been done 500x quicker had I done itdirectly on the server. My SQL knowledge is somewhat limited, however,so I had no choice but to stick to what I know, which is Cold Fusionprogramming.In the process of cleaning up some of these comma-delimited text files,I inadvertently messed up some of the 10-digit zip codes, by applyingthe wrong Excel formula to the ZIP columns. These records were importedinto the database with obviously incorrect zip codes (ie: singledigit). So now, I have to find the best and quickest way possible tocompare these records in the database (that have the single digit zipcodes) with the unmodified data, and to update the zip codes with thecorrect data.I've had no luck setting up a TEXT file as an ODBC datasource, -- soI've ruled that out completely. I've also managed to import theunmodified data into an Access database, and to set it up as a ColdFusion datasource. But it seems this 2nd road I've been traveling downis not the ideal approach either.My question is, -- assuming that I'll be able to import the recordsfrom the Access database into their own table on the SQL server, -- howshould I go about the process of updating these records that have theincorrect zip codes?Here is the specific logic I would need to employ:* Here is a list of records, each of which contains an incorrect1-digit zip code (Database A / Table A)* Here is a much longer list of records (which contains all of therecords from Database A / Table A + thousands more), each of whichcontains a correct 5-digit zip code (Database B / Table B)* Compare both lists of records and run the following query/update:When a record in Database A / Table A has matching "name", "address1",and "address2" values as a record in Database B / Table B -- update therecord in Database B / Table B with the zip code from the matchingrecord in Database A / Table A.Would anyone care to write a sample query for me that I could rundirectly on the SQL server, or at least give me some pointers?The specific field names are as follows:name,address1,address2,city,state,zipThanks in advance!- yvan
I like to give First Name and Last Name in two different text box and then hit the delete button (command button). Then it will do a query to find the person and delete the corresponding record from the table. Any kind of help will be appreciated. Thank you.
We're running a Sage CRM install with a SQL Server 2000 database at the back end. We're using the Sage web services API for updating data and a JDBC connection to retrieve data as it's so much quicker.
If I retrieve a record using the JDBC connection and then try and update the same record through the web services, the query times out as if the record is locked for updates. Has anyone experienced anything similar or know what I'm doing wrong? If I just use DriverManager.getConnection() to establish the connection instead of the datasource, and then continue with the same code I don't get these record locking problems. Please find more details below.
Thanks, Sarah
The JDBC provider for the datasource is a WebSphere embedded ConnectJDBC for SQL Server DataSource, using an implementation type of 'connection pool datasource'. We are using a container managed J2C authentication alias for logging on.
This is running on a Websphere Application Server v6.1.
Hi guys, I have a car_race table which has these fields
car_id int race_id int b_car_won varchar // can have 'y' or 'n'
I need to know if the car lost the 1st race but won the next race
And example of that table for car_id 1:
car_id 1 race_id 1 b_car_won 'NO'
car_id 1 race_id 2 b_car_won 'YES'
Now this is the tricky part, the database has some data integrity issues, so this can occur:
car_id 1 race_id 1 b_car_won 'NO'
car_id 1 race_id 3 b_car_won 'YES'
So I cant used a fixed race_id value, need to use the race_id > 1 to know whats the next race. But this raises another issue if I have this in the database:
car_id 1 race_id 1 b_car_won 'NO'
car_id 1 race_id 3 b_car_won 'YES'
car_id 1 race_id 4 b_car_won 'YES'
If I query I'd get 2 rows where race_id > 1. And I only need the first one, because 3 is the next race.
I need to fetch in a single row if possible, the result of the 1st race and the 2nd race. How can I do this?
select contractnbr,affcontractnbr,tdd,affrtramount,affturn, pt=datediff(d,afffirstfundingdate,affRTRBalanceZeroDate),ratio=datediff(d,afffirstfundingdate,affRTRBalanceZeroDate)/afftrun from #targetfinishedaff
datediff(d,afffirstfundingdate,affRTRBalanceZeroDate) appears two times in this code, Is there a way to make it appear only once? Thx
I have two SQL query that I would like to make in to one, if possibleHere is the first one: (Query4)SELECT rooms.DESCRIPTIO, rooms.ID, bookings1.DATEFROM bookings1 INNER JOIN rooms ON bookings1.ROOMID = rooms.IDWHERE (((bookings1.DATE) Between #4/3/2004# And #4/9/2004#));And the second one:SELECT rooms.ID, rooms.DESCRIPTIO, Query4.ROOMIDFROM rooms LEFT JOIN Query4 ON rooms.ID = Query4.ROOMIDWHERE (((Query4.ROOMID) Is Null));Is it possible to make one query of this two?With the same result.
I havea textbox for searching by patient name but now and though I am searching with LIKE% i can only search for exact string, for example if user typed JASSIM it will search for field full_name LIKE '%JASSIM%" ad if user typed JASSIM RAHMA it will search for full_name LIKE '%JASSIM RAHMA%' but i want to search if the field CONTAINS '%JASSIM% AND %RAHMA% when the user types JASSIM RAHAM in the textbox
Hi all. I have tried making this query for a while and i didn't manage to. I know it is something related to JOIN, but i didn't manage to make it work : I have two tables. Table1- db_stockprices Table2- db_stockSymbols
and so on for all the stocks. ID is Primary Key SymbolID is related to SymbolID in db_stockSymbols which contains all the stock information.
What i am trying to do is an SQL QUERY that will delete all same SymbolID Rows if a specific INPUT date do not exist within that SymbolID.
Example: If the INPUT date for the query is 1/3/2007 all rows with SymbolID "2" abd "4" will be deleted since 1/3/2007 does not exist in SymbolID "2" and "4". Moreover, the row in db_stockSymbols with SymbolID "2" and "4" will also be deleted.
Is this possible within 1 SQL Query? I would really appreciate a good query example for this example..
Hi, I got a problem. I installed Microsoft SQL Server Management Studio Express 2005 version. And I created a Compact database. I created an connection in SSMSE to connect the database and opened a query form. then, i run the following sql:
Select * from Table1
It returned 3 records to me. After that, I used program to insert record into this table. Then i ran this sql again, it still show me 3 records. I closed the query form, and re-created a new query form, then run the sql, it returned 4 records to me.
Why? It's very strange and difficult to operate, right? Is there anyone know how to make the SSMSE to return whole records without any close query form and re-create query form operation?
Hi, I have a query thatI need to make into one query for the sake of an application reading only one cursor.
Here's the syntax: select (select distinct(x.amount) from escrow k inner join e120 x on k.escrow = x.escrowinner join a10 g on x.escrow = g.escrow where k.ftype = 'S' group by x.amount, g.officer) As New,a.officer as Officer, count(distinct(j.fstatus))as Escrow_Type, count(distinct(j.amount))as Amount, count(distinct(d.open_date))as [Open], count(distinct(d.close_date)) as Closed, count(distinct(can_date))as Cancelled from a10 a inner join escrow d on a.escrow = d.escrowinner join e120 j on j.escrow = d.escrow where j.id_scr = 'e21' and j.fstatus = 'PAID' group by a.officer
The error message i'm recieving is the following:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I have table 'OrderTab' in Sql Server database which have Company Number,ContactId,Quantity fields and data in tables are in following format. Company ContactId QuantityNumber100001 101 1100001 102 2100001 103 9100001 104 8100001 105 4100001 106 3100001 107 2100001 108 1100001 109 3
I need to create the query and want the result in following format. CompanyNumber |MaxQuantityContactId |MaxQuantity| MinQuantityContactId |MinQuantity100001 103 9 101 1 Where MaxQuatityContactId = ContactId which has order max quantityMaxQuantity = max quantity order by single company(100001) MinQuatityContactId = ContactId which has order min quantityMinQuantity = min quantity order by single company (100001) Any idea how to do that. Thanks in AdvanceArvind
I need help makeing the following query run more efficently.
Code:
SELECT t1.ID,t1.firstName,t1.lastName,t1.address,t1.city,t1.state, t1.zip,t1.locationAddress,t1.locationCity,t1.locationState,t1.locationZip FROM Landlord_tbl t1 left outer join Mail_tbl t2 ON t2.potentialSitesID = t1.potentialSitesID WHERE t2.mailed_out_date is null and NOT(t1.firstName+t1.lastName) is Null GROUP BY t1.ID,t1.firstName,t1.lastName,t1.address,t1.city,t1.state, t1.zip,t1.locationAddress,t1.locationCity,t1.locationState,t1.locationZip ORDER BY t1.firstName, t1.lastName, t1.city, t1.state
Where, Opening column is 0 when there is no previous closing and Value column would be the daily total. The closing would be the Opening value + Daily Total and this value would Opening value for next line. Please help me how to write the SQL statement to get this result from above table.
I have encountered some problems creating MDX query. There are two input parameters on report, both dropdown list and from query. The first parameter will check "State", and the second parameter "Store Name" depends on previous' result. If there's no "State" found, I manage to show a "No Data" in the "State" droplist. But with "No Data" in first parameter, the second parameter simply is not enabled. I want the second parameter shows " No Data" as well but not succeed.
Here's code
...
SELECT {[Measures].[A1], [Measures].[B1], [Measures].[C1]} ON COLUMNS ,
[Store].[Store Name].ALLMEMBERS ON ROWS FROM ( SELECT ( STRTOSET(@State) ) ON COLUMNS FROM [Cube]) ... The query need to look at dataset that contains [store name] on rows, and some measures on columns. It also restricted by parameter @State.
Store Name that satisfies @State will be displayed. But if nothing from SELECT ( STRTOSET(@State) ) ON COLUMNS FROM [Cube], there's nothing in result. I'd rather like show something rather than nothing. I try codes like ... MEMBER [Store].[Store].[NA] AS '"N/A"' IIF(<Parameter empty>, (SELECT ... ON COLUMNS, [Store].[Store].[NA] ON ROWS FROM ...), (SELECT ...<Original statement >) ) ... It shows "Subselect support only Column axis".
Any one has an idea? Please help me out Many thanks!
If we use: select * from ..... , normally, it will return an ordered result ( may be order by ID ), but how can we make an random order select statement. It mean every time we run the query, the result will be different from the other ?
Any help would be really appreciated.... My stored procedure...
CREATE PROCEDURE business3rd7 @Fromdate DATETIME, @ToDate DATETIME AS
select distinct CONVERT(VARCHAR(10),Receipts.Companynumber1)+CONVE RT(VARCHAR(10),Receipts.Companynumber2) as co , Receipts.Premium1+Receipts.Premium2 as Premium, "CAN"=case when Receipts.transactiontype='CAN' then (receipts.premium1+receipts.premium2) else 0 end, "NET"=Receipts.Premium1+Receipts.Premium2-case when Receipts.transactiontype='CAN' then (receipts.premium1+receipts.premium2) else 0 end,
"#NEW"=case when Receipts.transactiontype='NEW' then count(Receipts.policynumber) else 0 end,
------- "$NEW"= case when Receipts.transactiontype='NEW' then (Receipts.Premium1+Receipts.premium2) else 0 end, "#REN"=case when Receipts.transactiontype='REN' then count(Receipts.policynumber) else 0 end, "$RENEW"= case when Receipts.transactiontype='REN' then (Receipts.Premium1+Receipts.premium2) else 0 end, "#AP"=case when Receipts.transactiontype='AP' then count(Receipts.policynumber) else 0 end, "$AP"= case when Receipts.transactiontype='AP' then (Receipts.Premium1+Receipts.premium2) else 0 end, "#SENT"=case when policy.Renewalofferdate between @Fromdate AND @ToDate then count(policy.policynumber) end,
"%"=case when case when Receipts.transactiontype='REN' then count(Receipts.policynumber)else 0 end =0 then 0 when case when policy.Renewalofferdate between @Fromdate AND @ToDate then count(policy.policynumber) else 0 end=0 then 0 else case when Receipts.transactiontype='REN' then count(Receipts.policynumber)else 0 end /case when policy.Renewalofferdate between @Fromdate AND @ToDate then count(policy.policynumber) else 0 end end,
"Current Year"= case when policy.Renewalofferdate between @Fromdate AND @ToDate then count(clubamount) end, "Previous Year"=case when policy.Renewalofferdate between DateAdd(year, -1, @Fromdate) AND DateAdd(year, -1, @ToDate) then count(clubamount) end, "#AA"=count(receipts.clubamount), "$AA"=sum(receipts.clubamount)
FROM Receipts,Policy where Receipts.Agencyid=Policy.Agentid group by Receipts.CompanyNumber1,Receipts.CompanyNumber2, Receipts.Premium1,Receipts.Premium2, Receipts.TransactionType,policy.Renewalofferdate, Receipts.Agencyid
I am currently stuck on how to make this 2 separate query work together, both work as i want them to individually, please note the syntax is according to a application i use that uses mysql to manipulate columns in an imported csv file.
CONCAT('at-', REPLACE([CSV_COL(18)],'http://www.homebuy.co.uk/product.php/','') ) removes last character i.e. / SUBSTRING([CSV_COL(18)], 1, CHAR_LENGTH([CSV_COL(18)]) - 1)
basically i need these 2 to work together to give me an output like this
at-09fd8903
from the this. URL...url above minus the "" as i said both work on there own, but not together.
select no_dossier from dbo.membre where date_MAJ = GETDATE()select no_dossier from dbo.membre where date_MAJ = '2005-07-21'Both should give me the same result, yes or no?thanks
select no_dossier from dbo.membre where date_MAJ = GETDATE()select no_dossier from dbo.membre where date_MAJ = '2005-07-21'Both should give me the same result, yes or no?thanks