Hi,
I want to write stored procedure in visual studio that as a parameter recieves the name of project and runs in database TT and copies data from TT.dbo.LCTemp (where the LC is the name of the project recieved as a parameter) table to "TT.dbo.Points" table. both tables have 3 columns:
PT_ID, Projectname and DateCreated
I think I have written it wrong, here it is:
ALTER PROCEDURE dbo.FromTmpToRegular
@project varchar(10)
AS
BEGIN
declare @ptID varchar(20)
declare @table varchar(20)
set @table = 'TT.dbo.' + @project + 'Temp'
set @ptID = @table + '.PT_ID'
Insert into TT.dbo.Points Select * from [@table] where [@ptID] Not in(Select PT_ID from TT.dbo.Points)
END
Any idea what I did wrong?
Thanks! :)
Greg
Hi,
I have never used datagrids and such, but today I came across a simple problem and decided to "databind" stuff to finish this faster, however I've found that it doesn't work as I was expecting.
I though that by doing something as simple as:
var q = from cust in dc.Customers
where cust.FirstName == someString
select cust;
var list = new BindingList<Customer>(q.ToList());
return list;
Then using that list in a DataGridView1.DataSource was all that I needed, however, no matter how much I google, I can't find a decent example on how to populate (for add/edit/modify) the results of a single table query into a DataGridView1. Most samples talk about ASP.NET which I lack, this is WinForms.
Any ideas?
I've came across other posts and the GetNewBindingList, but that doesn't seem to change much.
What am I missing (must be obvious)?
Thanks in advance.
Martin.
The State field in our database is a mess. There was no validation when it was filled so we have everything from two letter abbreviations to full state names to misspelled state names to "test" and "xxxx", etc.
I am not going to try to handle everything, but for sure I want to fix the correct state names to abbreviations.
I have a list of valid state names and abbreviations, but I don't know how I can do this:
UPDATE Table SET State = ('AR','AK') WHERE (SELECT * FROM Table WHERE State IN ('Arkansas','Alaska'))
Basically, can I update a field to be something from a list by the location it is in another list?
Hey there!
I've been racking my brain on how to do this for a while, and i know that some genius on this site will have the answer. Basically i'm trying to do this:
SELECT column
FROM table
WHERE [table][column] LIKE string1 OR [table][column] LIKE string2 OR [table][column] LIKE string3...
for a list of search strings stored in a column of a table. Obviously I can't do a like statement for each string by hand because i want the table to be dynamic.
Any suggestions would be great. :D
EDIT:
I'm using MSSQL :(
i have a parent report and it contains a two sub report.
* subreport: item
which get all fields from store procedure named spGetReportItem. like
ItemName ItemQuantity TotalItemCost
ab 4 45
dd 6 98
*subreport: Labour
which get all fields from store procedure named spGetReportLabour. like
labourName labourQuantity TotalLabourCost
ab 44 455
dd 63 986
i want to find the total of totalitemcost and total of totallabourcost and then want grandtotal of totalitemcost and totallabourcost.
i have seen many examples on internet in which shared variable is used in the formula bt the problem is that they have used the table but i m fetching data from stored procedure. so how can i access the stored procedure fields for calculation.
like i have seen that many have used:
shared numbervar total:=sum({tablename.ColumnName});
but i have used stored procedure instead of table so how could i find total of field that resultset returns from stored procedure..
plz give me answer as soon as possible..
i need it urgently.
thanks..
I want to retrieve the left 3 numbers from an integer to be stored in a table. For example, if the int is 1234567, I want to retrieve 123. I want the second number (123) to also be an int; I don't want to convert anything to a string.
(And yes, really I should be working with strings. But I don't have control over that aspect of the issue.)
Thank you!
I have two querys. Query 1 gives me this result:
Day New_Users
01-Jan-12 45
02-Jan-12 36
and so on.
Query 2 gives me this result:
Day Retained_Users
01-Jan-12 33
02-Jan-12 30
and so on.
I want a new query that will join this together and read:
Day New_Users Retained_Users
01-Jan-12 45 33
02-Jan-12 36 30
Do I use some sort of outer join?
Sorry* this is what I should have put
My query is creating duplicate entries for any record that has more than 1 instance (regardless of date)
<asp:SqlDataSource ID="EastMonthlyHealthDS" runat="server"
ConnectionString="<%$ ConnectionStrings:SNA_TRTTestConnectionString %>"
SelectCommand="SELECT [SNA_Parent_Accounts].[Company],
(SELECT [Monthly_HIP_Reports].[AccountHealth] from [Monthly_HIP_Reports] where ([Monthly_HIP_Reports].[YearMonth] = @ToDtRFC) AND ([SNA_Parent_Accounts].[CompID] = [Monthly_HIP_Reports].[CompID])) as [AccountHealth],
[SNA_Parent_Accounts].[CompID]
FROM [SNA_Parent_Accounts]
LEFT OUTER JOIN [Monthly_HIP_Reports] ON [Monthly_HIP_Reports].[CompID] = [SNA_Parent_Accounts].[CompID]
WHERE (([SNA_Parent_Accounts].[Classification] = 'Business') OR ([SNA_Parent_Accounts].[Classification] = 'Business Ihn')) AND ([SNA_Parent_Accounts].[Status] = 'active') AND ([SNA_Parent_Accounts].[Region] = 'east')
ORDER BY [SNA_Parent_Accounts].[Company]">
<SelectParameters>
<asp:ControlParameter ControlID="ddMonths" Name="ToDtRFC" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Using SELECT DISTINCT appears to correct the problem, but I don't consider that a solution. There are no duplicate entries in the database. So it appears my query is superfically creating duplicates.
The query should grab a list of companies that meet the criteria in the where clause, but also grab the Health status for each company in that particular [YearMonth] if present which is what the subquery is for. If an entry for that YearMonth is not present, then leave the Health status blank.
but as stated earlier.. if you have an entry say for 2009-03 for CompID 2 and an entry for 2009-04 for CompID 2.. Doesn't matter what month you select it will list that company 2-3 times.
Hi All,
I have a source column with blank (not "NULL"), and target as numeric. while converting using the data conversion it is not converting due to balnk source value so I used derived column to replace a blank value with NULL or 0 as
(source column == " ") ? "0" : source column
but its not giving the value as 0 in the blank place.
thanks
prav
I'm using a MySQL database and accessing it through Java.
PreparedStatement prep1 = this.connection.prepareStatement("UPDATE user_table
SET Level = 'Super'
WHERE Username = ?");
prep1.setString(1, username);
The update statement above works fine however I'd like to get the number of rows affected with this statement. Is this possible please?
Hi
I need to SELECT INTO a temp table multiple times with a loop but I just can't do it, because after the table created by SELECT INTO you can't simply drop the table at the end of the loop, because you can't delete a table and create it again in the same batch.
so how can I delete a table in a stored procedure and create it again?
is it possible to this without using a temp table?
here is a snippet of where I am actualy using the temp table which is supposed to be a pivoting algorithm:
WHILE @offset<@NumDays BEGIN
SELECT
bg.*, j.ID, j.time, j.Status
INTO #TEMP1
FROM #TEMP2 AS bg
left outer join PersonSchedule j on bg.PersonID = j.PersonID and
bg.TimeSlotDateTime = j.TimeSlotDateTime and
j.TimeSlotDateTime = @StartDate + @offset
DROP TABLE #TEMP2;
SELECT * INTO #TEMP2 FROM #TEMP1
DROP TABLE #TEMP1
SET @offset = @offset + 1
END
Hi I'm trying to output something like the following but am finding that there is a lot of code duplication going on.
| australian_has_itch | kiwi_has_itch |
| yes | no |
| no | n/a |
| n/a | no |
...
My query looks like this with two case statements that do the same thing but flip the country (my real query has 5 of these case statements):
SELECT
CASE
WHEN
NOT EXISTS (
SELECT person_id
FROM people_with_skin
WHERE people_with_skin.person_id = people.person_id
AND people.country = "Australia"
)
THEN 'N/A'
WHEN
EXISTS (
SELECT person_id
FROM itch_none_to_report
WHERE people.country = "Australia"
AND person_id = people.person_id
)
THEN 'None to report'
WHEN
EXISTS (
SELECT person_id
FROM itchy_people
WHERE people.country = "Australia"
AND person_id = people.person_id
)
THEN 'Yes'
ELSE 'No'
END australian_has_itch,
CASE
WHEN
NOT EXISTS (
SELECT person_id
FROM people_with_skin
WHERE people_with_skin.person_id = people.person_id
AND people.country = "NZ"
)
THEN 'N/A'
WHEN
EXISTS (
SELECT person_id
FROM itch_none_to_report
WHERE people.country = "NZ"
AND person_id = people.person_id
)
THEN 'None to report'
WHEN
EXISTS (
SELECT person_id
FROM itchy_people
WHERE people.country = "NZ"
AND person_id = people.person_id
)
THEN 'Yes'
ELSE 'No'
END kiwi_has_itch,
FROM people
Is there a way for me to condense this somehow and not have so much code duplication?
Thanks!
I have a table like this
UserID Score Date
5 6 2010-1-1
7 8 2010-1-2
5 4 2010-1-3
6 3 2010-1-4
7 4 2010-1-5
6 1 2010-1-6
I would like to get a table like this
UserID Score RunningTotal Date
5 6 6 2010-1-1
5 4 10 2010-1-3
6 3 3 2010-1-4
6 1 4 2010-1-6
7 8 8 2010-1-2
7 4 12 2010-1-5
Thanks!
hi guys,
I am getting result as decimal in storeprocedure.for eg:If iam getting result as 123.45
I want to split 123.45 to 123 and 45.Can any body help?
I have a table for logging that needs a log ID but I can't use an identity column because the log ID is part of a combo key.
create table StuffLogs
{
StuffID int
LogID int
Note varchar(255)
}
There is a combo key for StuffID & LogID.
I want to build an insert trigger that computes the next LogID when inserting log records. I can do it for one record at a time (see below to see how LogID is computed), but that's not really effective, and I'm hoping there's a way to do this without cursors.
select @NextLogID = isnull(max(LogID),0)+1
from StuffLogs where StuffID = (select StuffID from inserted)
The net result should allow me to insert any number of records into StuffLogs with the LogID column auto computed.
StuffID LogID Note
123 1 foo
123 2 bar
456 1 boo
789 1 hoo
Inserting another record using StuffID: 123, Note: bop will result in the following record:
StuffID LogID Note
123 3 bop
Sorry - my question title is probably as inept at my attempt to do this.
I have the following (well, similar) in a table in a CMS
pageID key value
201 title Page 201's title
201 description This is 201
201 author Dave
301 title Page 301's title
301 description This is 301
301 author Bob
As you've probably guessed, what I need is a query that will produce:
pageID title description author
201 Page 201's title This is page 201 Dave
301 Page 301's title This is page 301 Bob
If anybody could help, i'd be eternally grateful - I know this is "please send me the code" but I'm absolutely stuck.
Thanks in advance.
Hello, I have a table with measures and the time this measures have been taken in the following form: MM/DD/YYYY HH:MI:SS AM. I have measures over many days starting at the same time every day.The datas are minute by minute so basically the seconds are always = 0. I want to select only the measures for the first 5 minutes of each day. I would have used the where statement but the condition would only be on the minutes and note the date is there a way to do this?
Thanks
I have two tables reports and holidays.
reports: (username varchar(30),activity varchar(30),hours int(3),report_date date)
holidays: (holiday_name varchar(30), holiday_date date)
select * from reports gives
+----------+-----------+---------+------------+
| username | activity | hours | date |
+----------+-----------+---------+------------+
| prasoon | testing | 3 | 2009-01-01 |
| prasoon | coding | 4 | 2009-01-03 |
| prasoon | coding | 4 | 2009-01-06 |
| prasoon | coding | 4 | 2009-01-10 |
+----------+-----------+---------+------------+
select * from holidays gives
+--------------+---------------+
| holiday_name | holiday_date |
+--------------+---------------+
| Diwali | 2009-01-02 |
| Holi | 2009-01-05 |
+--------------+---------------+
Is there any way by which I can output the following?
+-------------+-----------+---------+-------------------+
| date | activity | hours | holiday_name |
+-------------+-----------+---------+-------------------+
| 2009-01-01 | testing | 3 | |
| 2009-01-02 | | | Diwali |
| 2009-01-03 | coding | 4 | |
| 2009-01-04 | Absent | Absent | |
| 2009-01-05 | | | Holi |
| 2009-01-06 | coding | 4 | |
| 2009-01-07 | Absent | Absent | |
| 2009-01-08 | Absent | Absent | |
| 2009-01-09 | Absent | Absent | |
| 2009-01-10 | coding | 4 | |
+-------------+-----------+---------+-------------------+
In other words I want to fill the activity and hours columns with "Absent" on the dates which are neither in table reports nor in table holidays. How can I write a specific query for it. The query should give the output between two specific dates.
I have a table in db2 which has the following fields
int xyz;
string myId;
string myName;
Example dataset
xyz | myid | myname
--------------------------------
1 | ABC.123.456 | ABC
2 | PRQS.12.34 | PQRS
3 | ZZZ.3.2.2 | blah
I want to extract the rows where myName matches the character upto "." in the myId field. So from the above 3 rows, I want the firs 2 rows since myName is present in myId before "."
How can I do this in the query, can I do some kind of pattern matching inside the query?
So I have a query, can someone let me know if it looks ok content wise?
"INSERT INTO ".TBL_MESSAGES." (NULL, 'Your ranking points have changed',
'Due to your recent activity, your ranking points have increased by $r', '2', '$u',
'0', '0', '0', '0', NULL, NULL, NULL, NULL, now())";
I can add further information if the query doesnt appear to have a problem?
Thanks
Hi, i have a query that returns something like this.
ID | Company| Total_Money | no_items | count_Total_Money_For_Company
-----------------------------------------------------------
1 | A | 1000 | 1 | 2001
2 | A | 1001 | 0 | 2001
3 | B | 1001 | 1 | 5010
4 | B | 1002 | 1 | 5010
5 | B | 1003 | 1 | 5010
6 | B | 1004 | 1 | 5010
7 | B | 1000 | 1 | 5010
How can i add that column with the count for that company?
I’m trying to design a database to use with ASP.net MVC application. Here is the scenario: There are three entities and users can post their comments for each of these different entities. I just wonder how just put one table for Comments and link all other entities to it. Obviously, Comments table needs 3 references (foreign key) to those tables but as you know these foreign keys can’t be null and just one of them can be filled for each row. Is there any better way than implementing three different tables for each entity’s comments?