Query To Fetch Data
Jul 23, 2005
Hi,
I have a table with two columns Task and Employee. It lists all the
tasks and the assigned employees. The same task will have multiple
roles with an employeename or 'manager' as the data.
If I have the following data
'sales', 'john'
'sales', 'manager'
'dev', 'manager'
'make_coffee', 'manager'
'browse', 'jane'
'browse', 'manager'
I need to get the rows wherever an employee is named (sales and browse
for example) and get manager for the rest.
I can make it in two queries. Look for not manager in one and then for
manager. Is there anyway to get them in a single query?
If I need to look for 'sales', I need to get 'john' and not 'manager'.
How to do that in a single query?
Another need is to list all tasks with assigned. So for the above, I
should get the following list
'sales', 'john'
'dev', 'manager'
'make_coffee', 'manager'
'browse', 'jane'
with two queries, I will get
'sales', 'john'
'browse', 'jane'
'dev', 'manager'
'make_coffee', 'manager'
which is ok. Order/sequence is not important.
TIA,
Sreelatha
View 2 Replies
ADVERTISEMENT
Mar 13, 2008
hi,
i want to be able to get the columns from my table except for its pk. the long method is to selecting all columns by listing them one by one right? but what if i got 100 columns..
so.. i wanted to use the information_schema..
i have:
use dbase;
select column_name
from information_schema.columns
where table_name = 'table1'
and column_name != 'pkid'
so there i'm listing the columns, but how am i suppose to select those columns from my real table?
thanks in advance!
View 4 Replies
View Related
Jun 29, 2012
Table has details like below:
NAME UPATE-TIMESTAMP
==== ===============
mary time1
mary time2
mary time3
tom time1
tom time2
tom time3
tom time4
richard time1
richard time2
Output Expected:
NAME UPATE-TIMESTAMP
==== ===============
mary time3
tom time4
richard time2
In summary, the requirement is to fetch the latest upated record for each unique NAME.
View 1 Replies
View Related
Dec 26, 2006
HelloThe problem is need to find out the querry that has updated or insertedinto the table and in turn 'Triggered the Trigger'. I have the username, the machine name, Application name, but not the query. The updateis not desired and the application is doing it but the applicationbeing so large we are unable to pin-point the code which is doing thedammage.Pls help!RegardsAnubhav
View 1 Replies
View Related
Sep 5, 2007
Hello..
i develope a web projects of horoscope or astrology(http://demo.reallianzbussimart.com/allzodiac.aspx), there is an 12 Zodiaz sign and all the data call on this page through the Database , in this page i there is an one sql query ---- (Select Top 1 col from colour order by newid(),Select Top 1 num from number order by newid() ,Select Top 1 days from day order by newid() )
then all data call one by one change ..
when the refresh the page the value of all zodiac is change that is wrong ,,,
so what is the quary that one time in day the value off all zodiac is same next day the value has been change............................................
so please help me /...........
tell what is the process to not data change into the page refresh
Ashwnai
View 4 Replies
View Related
Apr 13, 2007
Hi,
I'm using a remote SQL Server Express database with a C# app, and to do so as most of you already know, there's no DataSource available, it's all around SQL. This poses a problem as when I want to browse (1 by 1 in my app, with search utility) the contents of a given table, I have to perform a Select command. Well the problem is when I do this it loads all records into a DataSet (or DataTable), which is fine by me, but one of my tables is expected to reach 400 or 500 records in a few months time. This will mean a lot of loading from the db once the app is launched. Is there a way to make this connection more efective? Thanks
View 1 Replies
View Related
Jun 4, 2008
hi,im just a newbie in asp.net.i have my sqldatasource and a label. i want to get the data from sqldatasource to the label. how can i do that.need codes
View 2 Replies
View Related
Apr 2, 2001
Hi,
I have stored procedure with cursor
I have to use following
step 1 fetch RateValidDates into @Id_RateCode, @TheValidDate
.... get data
step 2 fetch prior from RateValidDates
... condition
step 3 fetch NEXT FROM RateValidDates into @Id_RateCode, @TheValidDate
... go to next record
Sql query analyzer output result of fetch NEXT FROM on the screen
What seeting should i use to avoid output on screen
(The reason My cursor takes about 8000 - 10000 rows when it's open)
View 1 Replies
View Related
Oct 11, 2007
My problem is that my:hustyp)[1] only fetches the first occurace of this tag. In my xmlfile this field is a repeating table created in infopath 2007. How do I manage to get the rest dynamically.
------XML-file---------------------------------------
<my:group1>
<my:group2>
<my:hustypTF>5</my:hustypTF>
</my:group2>
<my:group2>
<my:hustypTF>6</my:hustypTF>
</my:group2>
<my:group2>
<my:hustypTF>7</my:hustypTF>
</my:group2>
</my:group1>
-----------------------------------------------------
------T-SQL for fetching data from XML datatype------
WITH xmlnamespaces('http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-15T13:29:33' AS my)
SELECT FormData.value('(/my:xxx/my:Formular/my:group1/my:group2/my:hustyp)[1]', 'varchar(99)') AS IdFastBet
FROM MinaDekl
CROSS APPLY FormData.nodes('(/my:xxx/my:Formular/my:group1/my:group2/my:hustyp) as TempTab(testTab1)
-----------------
View 2 Replies
View Related
May 22, 2007
I am getting problem in fetching data from SQL using C++ program.
How to Fetch SQL Unicode characters?
I am using ODBC driver calls in C++ to fetch SQL data.
It is working fine with character data.
But for Unicode data it displays €œ????€? instead of data.
I am using SQL Server SQLSRV32.DLL for creating datasource.
Following is my code:
#include <windows.h>
#include <sqlext.h>
#include<srv.h>
#include<stdio.h>
#include <iostream.h>
#include <string.h>
int main(void)
{
void print_err2(RETCODE rc, SQLINTEGER type, SQLHANDLE handle);
HENV hEnv = NULL; // Env Handle from SQLAllocEnv()
HDBC hDBC = NULL; // Connection handle
HSTMT hStmt = NULL;// Statement handle
//UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "myDataSource";// Data Source Name buffer
USHORT *szDSN;
szDSN = (USHORT *) malloc (sizeof(USHORT) * 13);
szDSN= (unsigned short *)"myDataSource";
//UCHAR szUID[10] = "sa";// User ID buffer
USHORT *szUID;
szUID= (unsigned short *) "sa";
//UCHAR szPasswd[10] = "bmcAdm1n";// Password buffer
USHORT *szPasswd;
szPasswd= (unsigned short *) "bmcAdm1n";
char buff[9] = "Testing";
// UCHAR szSqlStr[128]= "INSERT into Quali (Colname) Values ('Testing')" ;
//UCHAR szSqlStr[150]= "select name ,default_database_name,default_language_name from sys.sql_logins" ;
USHORT *szSqlStr;
szSqlStr = (USHORT *) malloc (sizeof(USHORT) * 150);
szSqlStr= (unsigned short *) "select name ,default_database_name,default_language_name from sys.sql_logins" ;
RETCODE retcode;
//UCHAR sqlState; // buffer to store SQLSTATE
// UCHAR errMsg[256]; //buffer to store error message
// SWORD count;
USHORT *sqlState;
USHORT *errMsg;
sqlState= (USHORT *) malloc(sizeof(USHORT)*6);
errMsg= (USHORT *) malloc(sizeof(USHORT)*256);
SDWORD retcode3=NULL; // return code
SDWORD nativeErr; // native error code
SWORD realMsgLen; // real length of error message
// sprintf((char*)szSqlStr,"select name ,default_database_name,default_language_name from sys.sql_logins",buff);
// Allocate memory for ODBC Environment handle
cout<<"hEnv before SQLAllocEnv = "<<hEnv<<endl;
retcode= SQLAllocEnv (&hEnv);
cout<<"retcode= "<<retcode<<endl;
cout<<"hEnv after SQLAllocEnv = "<<hEnv<<endl;
cout<<"***********************";
// Allocate memory for the connection handle
cout<<"hDBC before SQLAllocConnect = "<<hDBC<<endl;
retcode= SQLAllocConnect (hEnv, &hDBC);
cout<<"retcode= "<<retcode<<endl;
cout<<"hDBC after SQLAllocConnect = "<<hDBC<<endl;
cout<<"***********************";
SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDBC);
// Connect to the data source using userid and password.
retcode = SQLConnect (hDBC, szDSN, SQL_NTS,szUID, SQL_NTS, szPasswd, SQL_NTS);
cout<<"retcode= "<<retcode<<endl;
if (retcode != SQL_SUCCESS )
{
retcode3 = SQLError(SQL_NULL_HDBC, hDBC, SQL_NULL_HSTMT, sqlState,&nativeErr,errMsg, 256, &realMsgLen);
// print_err(sqlState, nativeErr, errMsg, realMsgLen);
//print_err2(retcode,SQL_HANDLE_DBC,hDBC);
cout<<sqlState<<endl<<nativeErr<<endl<<errMsg<<endl<<realMsgLen;
}
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
cout<<"Connection established....!";
// Allocate memory for the statement handle
cout<<"hStmt before SQLAllocStmt = "<<hStmt<<endl;
retcode = SQLAllocStmt (hDBC, &hStmt);
cout<<"retcode= "<<retcode<<endl;
cout<<"hStmt after SQLAllocStmt = "<<hStmt<<endl;
cout<<"***********************";
/*
// Prepare the SQL statement by assigning it to the statement handle
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));
cout<<"Statement szSqlStr: "<<szSqlStr<<endl;
cout<<"Statement hStmt: "<<hStmt<<endl;
// Execute the SQL statement handle
retcode = SQLExecute (hStmt);
*/
retcode = SQLExecDirect(hStmt,szSqlStr, SQL_NTS);
UCHAR name[4000],defDBnm[4000],defLanguage[4000];
SDWORD retcode2, cbname, cbdefDBnm, cbdefLanguage;
retcode2=NULL;
if (retcode2 == SQL_SUCCESS)
{
retcode2 = SQLBindCol(hStmt, 1, SQL_C_CHAR, name, 4000, &cbname);
retcode2 = SQLBindCol(hStmt, 2, SQL_C_CHAR, defDBnm, 4000, &cbdefDBnm);
retcode2 = SQLBindCol(hStmt, 3, SQL_C_CHAR, defLanguage, 4000, &cbdefLanguage);
}
if (retcode2 != SQL_SUCCESS) /* warning or error returned */
{
retcode3 = SQLError(SQL_NULL_HDBC, hDBC, SQL_NULL_HSTMT, sqlState,&nativeErr,errMsg, 256, &realMsgLen);
//print_err(sqlState, nativeErr, errMsg, realMsgLen);
cout<<sqlState<<endl<<nativeErr<<endl<<errMsg<<endl<<realMsgLen;
}
cout <<"****************************************";
while (TRUE)
{
retcode2 = SQLFetch(hStmt);
if (retcode2 == SQL_SUCCESS || retcode2 == SQL_SUCCESS_WITH_INFO)
{
if (cbname == SQL_NULL_DATA) /* check null data */
printf("name: NULL");
else
printf("Name: %s", name);
if (cbdefDBnm == SQL_NULL_DATA)
printf("defDBnm name: NULL");
else
printf("defDBnm name: %s", defDBnm);
if (cbdefLanguage == SQL_NULL_DATA)
printf("defLanguage: NULL");
else
printf("defLanguage : %s", defLanguage);
}
else if (retcode2 == SQL_ERROR ) /* warning or error returned */
{
retcode3 = SQLError(SQL_NULL_HDBC, hDBC, SQL_NULL_HSTMT, sqlState,&nativeErr, errMsg, 256, &realMsgLen);
//print_err(sqlState, nativeErr, errMsg, realMsgLen);
cout<<sqlState<<endl<<nativeErr<<endl<<errMsg<<endl<<realMsgLen;
}
else /* if no more data or errors returned */
break;
}
// Project only column 1 which is the models
// SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);
// Get row of data from the result set defined above in the statement
// retcode = SQLFetch (hStmt);
// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);
// Disconnect from datasource
SQLDisconnect (hDBC);
}
// Free the allocated connection handle
SQLFreeConnect (hDBC);
// Free the allocated ODBC environment handle
SQLFreeEnv (hEnv);
return 0;
}
void print_err2(RETCODE rc, SQLINTEGER type, SQLHANDLE handle)
{
//SQLCHAR SqlState, *sq = &SqlState[0];
SQLUSMALLINT *SqlState;
SqlState=(SQLUSMALLINT *) malloc (sizeof(SQLUSMALLINT)*6);
SQLUSMALLINT *sq = &SqlState[0];
SQLCHAR Msg[SQL_MAX_MESSAGE_LENGTH], *ms = &Msg[0];
SQLWCHAR SqlStateW, *sqw = &SqlStateW[0];
SQLWCHAR MsgW[SQL_MAX_MESSAGE_LENGTH], *msw = &MsgW[0];
SQLINTEGER NativeError;
SQLSMALLINT i=1, MsgLen;
RETCODE ret;
int j;
printf("Error number is %d", rc);
while (SQL_SUCCEEDED(SQLGetDiagRec(type, handle, i++,(unsigned short *) SqlState, &NativeError, (unsigned short *)Msg, sizeof(Msg), &MsgLen)) )
{
printf("State: %s Native Error Code: %d %s (%d)",
SqlState,NativeError,Msg, MsgLen);
}
}
Regards
Ketaki
View 3 Replies
View Related
Feb 3, 2005
Having two tables.
1. ID Year
----------
1 1990
2 1991
3 1992
2. Name Year
--------------
ABC 1
XYZ 2
123 3
By passing year as an argument, Want to retrieve all the Names that does not have records for that particular year.
For example, if pass 1990, then the result set should be 'XYZ' and '123'
Thanks in advance
View 2 Replies
View Related
Nov 15, 2013
I have a dropdown list with checkbox and when I select multiple options and search, its returning only the last selected value in the grid. Here is the code I use it for search. Designation is the column where I bind its values to the checkbox.
Checkbox tag:
<asp:CheckBoxList ID="cblGroup" Style="vertical-align: baseline" runat="server" CssClass="chkbox">
</asp:CheckBoxList>
Select Query:SqlCommand cmd = new SqlCommand("select * from AppInvent_Test where Designation= '" + cblGroup.SelectedValue + "'", con);
View 2 Replies
View Related
Aug 29, 2007
I do an insert of the xml into the table and that works fine, but how do I split the tags to different tables. I have tried SSIS and a XML Source to an OLEDB Source, but since the xml file contains different groups that do not work.
The xml is created by Infopath and it seems like the groups are created if the components belongs to different sections.
Table1
id int,
xmltag xml
I am starting to be desperate, I really need some help solving this one way or another.
View 2 Replies
View Related
Feb 12, 2014
I created a view with a simple join query
there are 2 rows with orderid as null, i am unable to fetch the details when i give WHERE Condition as
"select orderid from joins where orderid=NULL"
Query :
create view joins as
select A.customerid,A.Companyname,A.Contactname,A.City,B.OrderId from Customers A
left join orders B
on A.Customerid=B.Customerid
View 1 Replies
View Related
Mar 26, 2003
Hi,
I am using DTS (Data Pump Task) to fetch selective data from AS/400. The Selection is based on a table which is on SQL Server.
I can not fetch the whole data as data is huge & only want for particular items. How can I achieve this taks
Thanks
Shafiq
:confused:
View 6 Replies
View Related
Aug 6, 2007
I only found first or last function which means I can't show the data of others, is there any solution to solve this issue?
Thanks in advance.
View 4 Replies
View Related
Apr 21, 2008
Hi,
I am using SQL Server 2005 Mobile Edition & Merge Replication
in this I want to insert a record into table,
in that table I have taken UserID coloumn as auto incrementing Identity type.
In a book I read that,
If you are using an Identity column, you must find the next available number and reseed before an insert can be successful. You will also have to set up ranged identity columns on the published database to prevent errors when the new data is merged.
Now I want to ask here that, how should I ressed that value before inserting?????
any help in a form of CODe will be appriciated.....
thanks in advance...
View 8 Replies
View Related
Oct 31, 2015
I was working on a logic which I am not able to code after many attempts. I have an Excel sheet(Base_Data.xlsx) with two sheets as "Mapping" & "Data" with the below data:
Mapping sheet values:
Base_Column Data_Column
Employee Emp
Designation Desig
Organisation Org
Data sheet values:
Emp joindate Desig Gender Org
1234 10/10/2010 Consultant Male Microsoft
4546 25/01/2001 Sw engineer Female Pega
Now using the above base_Data file, I have a to prepare a destination Excel(Destination_File.xlsx) as below:
Employee Designation Organisation
1234 Consultant Microsoft
4546 Sw engineer Pega
I tried to achieve this using SSIS and C#.Net technologies.
View 3 Replies
View Related
Oct 14, 2015
how to fetch data from oracle database in sql server 2014
example:
oracle schema :t1
sql server :t2
now am in t2 sql server database
now am executing below query
select * from t1.tablename ;
View 1 Replies
View Related
Apr 21, 2015
I need the rows updated today in catalogue table irrelevant of timing. I tried all the below queries.
select * from CATALOGUE where CAT_DATE=CONVERT(datetime, CONVERT(varchar, GETDATE(), 101))
select * from CATALOGUE where CAT_DATE= CONVERT(date, getdate())
select * from CATALOGUE where CAT_DATE= cast(GETDATE() as date)
I am getting output only if the information updated on 04/21/2015 00.00.00.000 but not for other timings, For example
04/21/2015 03.30.00.000, 04/21/2015 07.17.00.000 and all.
How can I retrieve all the records updated today.
View 4 Replies
View Related
May 2, 2015
I have added one webpage designed in ASP.Net with C# and sql server 2005 as database. There is table for user registration in which there is a column for ProfileCreationDate the data type of that column is date time .
I would like to fetch data of those user who have created profile within 7 days. For getting desired result I am trying this query.
select Name ,Profession,ProfileCreationDate from tblRegistration where DATEDIFF ( Day , '" + System.DateTime.Now + "',ProfileCreationDate)<7 order by ProfileCreationDate DESC
System.DateTime.Now is a function for getting current date time in C#
The query is neither giving error nor giving desired result.
View 4 Replies
View Related
Oct 21, 2015
I have been trying to write a cursor to fetch required data from table but somehow its running forever and inserting duplicate records.
I have a temp table named getInvoice where I have five important columns
1. invoice number
2.group
3.invoice status
4. Invoice Expiration date
5. Creation date time
and some other columns.One invoice number can belong to one or more group and there can be one or more records for a particular invoice number and group.
An example is below :
InvoiceNumber Group InvoiceStatus InvoiceExpirationDate CreationDateTime
579312 01 3 NULL 2003-03-24 00:00:00
579312 01 2 2015-12-14 00:00:00 2005-12-24 00:00:00
579312 02 2 2003-12-21 00:00:00 2005-10-12 00:00:00
321244 01 2 2015-12-21 00:00:00 2005-10-12 00:00:00
321244 01 3 2010-12-21 00:00:00 2010-12-21 00:00:00
My query condition is complex and that is why Im facing problem retrieving the output.I need a cursor for getting distinct invoice number from the table and for each invoice number I need to get the latest record for each invoice number and suffix combination based on creationdateand time column and if that record has invoice status of 2 and also the invoice expiration date can be either null or greater than today's date, then I need to get that record and put it in a temp table.
The query I wrote is below
declare myData cursor for
select distinct invoiceNumber from #getInvoice
declare @invoiceNumber varchar(30)
open myData
fetch next from myData into @invoiceNumber
while @@FETCH_STATUS = 0
[Code] .....
This query runs forever and doesn't stop.
View 6 Replies
View Related
Apr 21, 2015
I am currently working with C and SQL Server 2012. My requirement is to Bulk fetch the records and Insert/Update the same in the other table with some business logic? How do i do this?
View 14 Replies
View Related
Aug 7, 2015
I have an excel sheet containing one column (ID_NO) with 400K rows. I have a database from where I have to fetch some other columns from a Netezza database. Initially I tried hardcoding all the 400K rows in the query that I wrote using filter WHERE ID IN ('1212','2334'). But after pasting all the 400K rows the query is running indefinitely.
I have imported all the ID in a SQL table (MY_LIST table). I used a DFT, and selected ODBC source, and selected my netezza server. Then in the 'Data access mode' I selected the SQL command from the dropdown.I pasted the same query that I wrote in Netezza. Is there any way to pull only for those records that I have pulled in my SQL table (MY_LIST) ?
View 4 Replies
View Related
Jun 12, 2004
Is it possible to have fetch within a fetch? I am getting this error message "A cursor with the name 'crImgGrp' does not exist." So i separate the process into two stored procedures?
CREATE PROCEDURE TrigSendPreNewIMAlertP2
@REID int
AS
Declare @RRID int
Declare @ITID int
Declare @intIMEmail varchar(300)
Declare crReqRec cursor for
select RRID from RequestRecords where REID = @REID and RRSTatus = 'IA' and APID is not null
open crReqRec
fetch next from crReqRec
into
@RRID
Declare crImpGrp cursor for
select ITID from RequestRecords where RRID = @RRID
open crImpGrp
fetch next from crImgGrp
into
@ITID
while @@fetch_status = 0
EXEC TrigSendNewIMAlertP2 @ITID
FETCH NEXT FROM crImpGrp
into
@ITID
close crImpGrp
deallocate crImpGrp
while @@fetch_status = 0
FETCH NEXT FROM crReqRec
into
@RRID
close crReqRec
deallocate crReqRec
GO
View 1 Replies
View Related
Jun 22, 2004
Let's say i have 5 unique RRID's, column APID and ITID
RRID - APID - ITID
1 13 700
2 13 700
3 13 700
4 14 700
5 15 700
If I run the stored procedure below, I get the results above however, I want my result to be
RRID - APID - ITID
1 13 700
2 13 700
3 13 700
4 14 701
5 15 702
I want my cursor to loop at the same APID then assign one ITID then move to the next APID and so on...
Any help is highly appreciated....
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
ALTER PROCEDURE InsNewEmployeeImpTaskP2
@REID int,
@LOID int,
@RetValintoutput
AS
Declare @RRID int
Declare @APID int
Declare @intREID varchar(20)
Declare @intIMID varchar(20)
Declare crReqRec cursor for
select RRID from RequestRecords where REID = @REID and RRSTatus = 'AC' and APID is not null
open crReqRec
fetch next from crReqRec
into
@RRID
set @APID = (select APID from RequestRecords where REID = @REID and RRID = @RRID)
set @intIMID = (SELECT ImplementationGroup.IMID
FROM ImplementationGroup_Location INNER JOIN
ImplementationGroup ON ImplementationGroup_Location.IMID = ImplementationGroup.IMID INNER JOIN
Applications_ImplementationGroup ON ImplementationGroup.IMID = Applications_ImplementationGroup.IMID where APID = @APID and ImplementationGroup_Location.LOID = @LOID )
insert into ImplementationTasks
(
IMID,
ITStatus,
ITStatusDate
)
VALUES
(
@intIMID,
'2',
GetDate()
)
SET @RetVal = @@Identity
while @@fetch_status = 0
Begin
Update RequestRecords
set ITID = @RETVal, RRStatus = 'IA'
where REID = @REID and RRID = @RRID
FETCH NEXT FROM crReqRec
into
@RRID
end
close crReqRec
deallocate crReqRec
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
View 1 Replies
View Related
Nov 30, 2004
i am having an endless loop after the first record.... anything i missed?
ALTER PROCEDURE IMPGrpEscalationX
AS
Declare @IMID int
Declare @IMID2 int
Declare @FS1 int
Declare @FS2 int
Declare crFirst cursor local for
select IMID from ImplementationGroup where IMSTatus = 'Y'
open crFirst
fetch next from crFirst
into
@IMID
begin
Declare crSecond cursor local for
select IMID from Employees_ImplementationGroup where Employees_ImplementationGroup.IMID = @IMID
open crSecond
fetch next from crSecond
into
@IMID2
set @FS2 = @@fetch_status
if not exists(select IMID from Employees_ImplementationGroup where IMID = @IMID2 and IMType = 'T')
Begin
DECLARE @MsgText varchar(700)
DECLARE @IMGRPNAME varchar(50)
Set @IMGRPNAME = (select IMGrpname from ImplementationGroup where IMID = @IMID2)
--SET @MsgText = 'This implementation group has been without a last resort implementer for the past 24 hours. Please click here to assign a last resort implementer: http://xxxx.com/admin/implementationgrp_emps.aspx?imid=' + @IMID2 + '&imgrpname=' + @IMGrpName
EXEC master.dbo.xp_sendmail
@recipients = cccc@ccc.com',
@Message = @IMGRPNAME,
@Subject = 'needs attention'
end
while @FS2 = 0
fetch next from crSecond
into
@IMID2
end
set @FS1 = @@fetch_status
while @FS1 = 0
FETCH NEXT FROM crFirst
into
@IMID
close crFirst
deallocate crFirst
close crSecond
deallocate crSecond
View 1 Replies
View Related
Apr 3, 2008
I need to see the records from two tables where the mobilenumbers are not same.
I have two tables named as messages and subscribers with Id, MobileNumber fields.
Now here I need to see the records where the mobile number exist in one table but not in other table.
Please give me the sql query for this.
with regards
Shaji
View 7 Replies
View Related
Apr 2, 2015
I want to fetch all bills (except cancelled bills) for a given month and fetch the previous bill date.
This is to find out the frequency of a vehicle visit to a workshop.
Sample Data
Division,ChasNo,BillDt,Status
D1,C1,01/01/2015,Null
D1,C1,15/01/2015,Null
D1,C1,23/02/2015,Null
D2,C1,26/02/2015,Null
D2,C2,02/01/2015,Null
D2,C2,16/01/2015,Null
D2,C2,21/02/2015,Null
D1,C3,24/01/2015,Cancelled
Result Expected
D1,C1,23/01/2015,15/01/2015
D2,C1,26/02/2015,Null
D2,C2,21/02/2015,16/01/2015
What I tried is
Declare @Mh smallint,@Yr smallint
Select @Mh=2,@Yr=2015
Select Division,ChasNo,BillDt Into #CMBills from Service_Bills Where Month(BillDt)=@Mh and Year(BillDt)=@Yr and Status Is Null
Select SB.Division,SB.ChasNo,CMB.BillDt as CurBillDt,Max(SB.BillDt) as PreBillDt,Datediff(day,Max(SB.BillDt),Max(CMB.BillDt)) as DiffDays from #CMBills CMB
Left Join Service_Bills SB On SB.Division=CMB.Division and SB.ChasNo=CMB.ChasNo and SB.Status Is Null and SB.BillDt<CMB.BillDt
Group By SB.Division,SB.ChasNo,CMB.BillDt
But I'm not getting details for all the bills I fetched.
View 4 Replies
View Related
May 21, 2007
How can I fetch only Odd or only even records from a table.The odd or even is depends up on Id (Its a primary key/ Integer).
Is there any query
Please help me!
Shaji
View 9 Replies
View Related
Dec 3, 2007
Hi Folks,
How do I right queries to fetch first 10 records, then next 10 and so on..
My table structure is as follows:
Columns
--------
MPAD_ID (IDENTITY INCREMENT YES )
MPAD_EmpCode (Employee Code)
MPAD_Date (Date)
MPAD_Status (Attendance Status i.e. P, A, etc)
Sample Records for the same is given below
MPAD_ID MPAD_EmpCode MPAD_Date MPAD_Status
------- ------------ ---------- -----------
1 1001 11/01/2007 P
2 1001 11/02/2007 P
3 1001 11/03/2007 A
... .. .. ..
14 1002 11/01/2007 P
15 1002 11/02/2007 A
16 1002 11/03/2007 P
Please help me out in writing out this query.
Thanks
Jabez.
View 3 Replies
View Related
Jul 20, 2005
I have a stored procedure that inserts one row into a table. From aSELECT statement I would like to call the SP on each row in theresults. Is setting up a cursor and using fetch statements the bestway (or even the only way) to do this?
View 1 Replies
View Related
Jul 20, 2005
Hello everyone, hope someone can help me with this.I have a SQL stored procedure that inserts a record into a table,creates a cursor to fetch the last record that was added to get theunique key that was created and then writes that and other info to aseparate table. This procedure was working fine at our ISP under NT 4and SQL 7.We recently moved to another ISP on servers that are windows 2000 andSQL 2000. Now this code is going kerplooey. It actually worked finein the staging area but now that it was moved into production, it isnot working. also wanted to mention that the production database wasrestored from a backup. below is the code.the first time this is run it is ok, for example the transactionnumber is 1. the next time it is run, a new record is created in thesweep results with a transaction number of 2. but for some reason,when i declare the cursor to fetch the last record, it goes back tothe transaction number 1 record. so the counts from transaction 1don't match counts from transaction 2 and the next step has an errorcondition and doesn't work.thanks in advance for any help you can provideAnn Williams-- update the sweep results tableINSERT tbl_sweepresults (del_wrkfeedback_count,updnull_feedback_count, swp_feedback_count,swp_count_error, del_error, updnull_error, swp_error, init_error,sweep_date)VALUES (@var_del_wrkfeedback_count, @var_updnull_feedback_count,@var_swp_feedback_count,@var_swp_count_error, @var_del_error, @var_updnull_error,@var_swp_error, @var_init_error, GETDATE())-- create cursorDECLARE tbl_sweepresults_cursor SCROLL CURSOR FORSELECT transaction_no, sweep_date, init_error, updnull_feedback_countFROM tbl_sweepresultsOPEN tbl_sweepresults_cursor-- get transaction number, sweep date, init error, feedback sweepcount and pass to tbl_currentTrans for OPAL comparisonFETCH LAST FROM tbl_sweepresults_cursor INTO @var_transaction_no,@var_sweep_date, @var_init_error, @var_swp_countzeroDELETE tbl_currentTransINSERT tbl_currentTrans (current_transaction_no, current_sweep_date,current_init_error, current_swp_countzero)VALUES (@var_transaction_no, @var_sweep_date, @var_init_error,@var_swp_countzero)-- close the cursorCLOSE tbl_sweepresults_cursorDEALLOCATE tbl_sweepresults_cursor
View 1 Replies
View Related