How To Write A SQL Update Query Using Parameters?
Mar 23, 2008Hi, could someone explain to me with sample code how to write a sql query using parameters to update a record, as I am new to this.
thanks
Hi, could someone explain to me with sample code how to write a sql query using parameters to update a record, as I am new to this.
thanks
For example:
Select * From Customers Where CustomerName = "Tom" and CustomerLocation = @Location
I know MS Access you can use a "*" to retrieve all records when there is a parameter. What does SQL Sever query use to retrieve all record?
I would like to write a query that will join two tables in separate databases (same server). Then update a field in one table using data and criteria from the other.
Its easy to do this in Microsoft Access by linking the tables using ODBC, but I found its not so simple to do directly in SQL Server
Thanks.
I have a web form that is populated from the DB values. User can update teh record by keying in new values in the form fields. In my .vb class file I have an update statement -
strSql = "UPDATE msi_Persons SET Firstname=@firstname where Id=@id"
I have the parameters defined as
cmd.Parameters.Add(New SqlParameter("@firstname", _FirstName))
cmd.Parameters.Add(New SqlParameter("@id", _Id))
_FirstName & _Id are the private variables whose values a set thru set and get methods. I expect _FirstName to have the new value I am keying in the form.
Can any body help me with what's wrong here? This is not updating the database. When I do trace.write it shows me the Update statement as "UPDATE msi_Persons SET Firstname=@firstname where Id=@id" instead of @firstname and @id being replace by actual values.
Please help.
Thanks,Shaly
How to write stored procedure with two parametershow to check those variables containing values or empty in SP
if those two variables contains values they shld be included in Where criteiriea in folowing Query with AND condition, if only one contains value one shld be include not other one
Select * from orders plz write this SP for me thanks
Hello All,
As we have INSERTED,DELETED tables to trace what values are inserted and deleted, how to write triggers for Updates on the tables.
Your help would be appreciated.
Shiva Kumar
Hi, this SQL:
UPDATE [dbo].tblCommodity SET sImagePath .WRITE('abcdef', 0, 5)
gives me following error:
Cannot call methods on varchar.
I did it same way as it is in SQL Server Online Help :(
Thanks for ideas,
Martin
I have these 3 tables that are related to each other. I am trying to change the brand name of a product and the type of the product. How can I do this? 1 CREATE TABLE Products
2 (
3 ProductID int IDENTITY (1,1) PRIMARY KEY,
4 ProductSKU nvarchar(100) NOT NULL UNIQUE,
5 ProductName nvarchar(255),
6 ProductDescription nvarchar(MAX),
7 isInStock bit,
8 SalePrice decimal (18,2),
9 UnitPrice decimal (18,2),
10 isOnSale bit,
11 isSpecial bit,
12 isActive bit,
13 ProductRating int,
14 ProductImageBig varchar(255),
15 ProductImageMedium varchar(255),
16 ProductImageSmall varchar(255)
17 );
18
19 CREATE TABLE Brands
20 (
21 BrandID int IDENTITY (1,1) PRIMARY KEY,
22 BrandName nvarchar(255) NOT NULL UNIQUE
23 );
24
25 CREATE TABLE Types
26 (
27 TypeID int IDENTITY (1,1) PRIMARY KEY,
28 TypeName nvarchar(150) NOT NULL UNIQUE
29 );
30
31 // The store procedure I am having trouble with.
32
33 CREATE PROC SetProductsSKU_Brand_Type
34 @ProductID int,
35 @BrandName nvarchar(255),
36 @TypeName nvarchar(150),
37 @ProductSKU nvarchar(100),
38 @ProductName nvarchar(255),
39 @isInStock bit,
40 @SalePrice decimal (18,2),
41 @UnitPrice decimal (18,2),
42 @isOnSale bit,
43 @isSpecial bit,
44 @isActive bit
45 AS
46 UPDATE Products, Types, Brands
47 SET [BrandName] = @BrandName, [TypeName] = @TypeName, [ProductSKU] = @ProductSKU, [ProductName] = @ProductName, [isInStock] = @isInStock,
48 [UnitPrice] = @UnitPrice, [isSpecial] = @isSpecial, [isActive] = @isActive
49 FROM Products prod INNER JOIN ProductsBrands pb
50 ON prod.ProductID = pb.ProductID INNER JOIN Brands b
51 ON pb.BrandID = b.BrandID INNER JOIN ProductsTypes tp
52 ON prod.ProductID = tp.ProductID INNER JOIN Types t
53 ON tp.TypeID = t.TypeID
54 WHERE prod.ProductID = @ProductID
55 AND [ProductSKU] = @ProductSKU
56 AND [ProductName] = @ProductName
57 AND [isInStock] = @isInStock
58 AND [UnitPrice] = @UnitPrice
59 AND [isSpecial] = @isSpecial
60 AND [isActive] = @isActive
61 AND b.BrandName = @BrandName
62 AND t.TypeName = @TypeName
Hi folks,
Do you guys know how to write the Script to update the SQL database? please help me out? For example, the script will update SQL database at 1:00 am every day...some like that?
Thanks,
Vu
hi there, i have been wrestling with this for quite a while, as in my other post http://forums.asp.net/t/1194975.aspx, what someone advised me was to put in try catch blocks ot see whats going on, problem is i have never really done it whit this kinda thing before, and i was wondering if someone could point me in the right direction.
For example where would i put the try catch block in here, to show me if its not working public int getLocationID(int ProductID, int StockLoc)
{
// Gets the LocationID (Shelf ID?) for the stock column and product id
// passed
// The SQL will look Something like: string strSQL;
strSQL = "SELECT " + " location" + StockLoc + " " + "FROM " + " tbl_stock_part_multi_location " + "WHERE " + " stock_id = " + ProductID;string sConnectionString = "Data Source=xxxxx;Initial Catalog=xxxx;User ID=xxxx;Password=xxxxx";
SqlConnection objConnGetLocationID = new SqlConnection(sConnectionString);SqlCommand sqlCmdGetLocationID = new SqlCommand(strSQL, objConnGetLocationID);
objConnGetLocationID.Open();int intLocation = Convert.ToInt32(sqlCmdGetLocationID.ExecuteScalar());
return intLocation;
}
I have the following table:
CREATE TABLE [dbo].[IntegrationMessages]
(
[MessageId] [int] IDENTITY(1,1) NOT NULL,
[MessagePayload] [varbinary](max) NOT NULL,
)
I call the following insertmessage stored proc from a c# class that reads a file.
ALTER PROCEDURE [dbo].[InsertMessage]
@MessageId int OUTPUT
AS
BEGIN
INSERT INTO [dbo].[IntegrationMessages]
( MessagePayload )
VALUES
( 0x0 )
SELECT @MessageId = @@IDENTITY
END
The c# class then opens a filestream, reads bytes into a byte [] and calls UpdateMessage stored proc in a while loop to chunk the data into the MessagePayload column.
ALTER PROCEDURE [dbo].[UpdateMessage]
@MessageId int
,@MessagePayload varbinary(max)
AS
BEGIN
UPDATE [dbo].[IntegrationMessages]
SET
MessagePayload.WRITE(@MessagePayload, NULL, 0)
WHERE
MessageId = @MessageId
END
My problem is that I am always ending up with a 0x0 value prepended in my data. So far I have not found a way to avoid this issue. I have tried making the MessagePayload column NULLABLE but .WRITE does not work with columns that are NULLABLE.
My column contains the following:
0x0043555354317C...
but it should really contain
0x43555354317C...
My goal is to be able to store an exact copy of the data I read from the file.
Here is my c# code:
public void TestMethod1()
{
int bufferSize = 64;
byte[] inBuffer = new byte[bufferSize];
int bytesRead = 0;
byte[] outBuffer;
DBMessageLogger logger = new DBMessageLogger();
FileStream streamCopy =
new FileStream(@"C:vsProjectsSandboxBTSMessageLoggerInSACustomer3Rows.txt", FileMode.Open);
try
{
while ((bytesRead = streamCopy.Read(inBuffer, 0, bufferSize)) != 0)
{
outBuffer = new byte[bytesRead];
Array.Copy(inBuffer, outBuffer, bytesRead);
string inText = Encoding.UTF8.GetString(outBuffer);
Debug.WriteLine(inText);
//This calls the UpdateMessage stored proc
logger.LogMessageContentToDb(outBuffer);
}
}
catch (Exception ex)
{
// Do not fail the pipeline if we cannot archive
// Just log the failure to the event log
}
}
Hi,
I have an app in C# that executes a query using SQLCommand and parameters and is taking too much time to execute.
I open a SQLProfiler and this is what I have :
exec sp_executesql N' SELECT TranDateTime ... WHERE CustomerId = @CustomerId',
N'@CustomerId nvarchar(4000)', @CustomerId = N'11111
I ran the same query directly from Query Analyzer and take the same amount of time to execute (about 8 seconds)
I decided to take the parameters out and concatenate the value and it takes less than 2 second to execute.
Here it comes the first question...
Why does using parameters takes way too much time more than not using parameters?
Then, I decided to move the query to a Stored Procedure and it executes in a snap too.
The only problem I have using a SP is that the query can receive more than 1 parameter and up to 5 parameters, which is easy to build in the application but not in the SP
I usually do it something like
(@CustomerId is null or CustomerId = @CustomerId) but it generate a table scan and with a table with a few mills of records is not a good idea to have such scan.
Is there a way to handle "dynamic parameters" in a efficient way???
My problem is that I can' t update my gridview. I am stuck at this problem for several days now and have no clue what the sollution could be. Hope somebody can give me some ideas of what I am doing wrong.
<asp:GridView ID="GridView_phl_berichten" runat="server" AutoGenerateColumns="False" BorderColor="DimGray" BorderStyle="Solid" BorderWidth="1px" DataKeyNames="phlb_id" DataSourceID="SqlDataSource_phl_berichten" GridLines="Horizontal" Width="716px">
<Columns>
<asp:TemplateField HeaderText="Van datum" SortExpression="phlb_van">
<EditItemTemplate>
<asp:Calendar ID="phlb_van" runat="server" SelectedDate='<%# eval("phlb_van") %>'
VisibleDate='<%# eval("phlb_van") %>'></asp:Calendar>
</EditItemTemplate>
<ItemStyle VerticalAlign="Top" Width="5cm" />
<ItemTemplate>
<asp:Label ID="Label_datum_van" runat="server" Text='<%# eval("phlb_van", "{0:d}") %>'></asp:Label>
<br />
<br />
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete" OnClientClick=" return confirm('Bent u zeker dat u dit bericht wil verwijderen ?') "></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tot datum" SortExpression="phlb_tot">
<EditItemTemplate>
<asp:Calendar ID="phlb_tot" runat="server" SelectedDate='<%# eval("phlb_tot") %>'
VisibleDate='<%# eval("phlb_tot") %>'></asp:Calendar>
</EditItemTemplate>
<ItemStyle VerticalAlign="Top" Width="4cm" />
<ItemTemplate>
<asp:Label ID="Label_datum_tot" runat="server" Text='<%# eval("phlb_tot", "{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Bericht" SortExpression="phlb_bericht">
<EditItemTemplate>
<asp:TextBox ID="phlb_bericht" runat="server" Height="98px" Text='<%# eval("phlb_bericht") %>'
TextMode="MultiLine" Width="527px"></asp:TextBox><br />
<br />
<asp:LinkButton ID="LinkButtonUpdate" runat="server" CausesValidation="False" CommandName="Update"
Font-Size="Small" OnClientClick="return confirm('Bent u zeker dat u dit bericht wil opslaan ?')"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButtonCancel" runat="server" CausesValidation="False" CommandName="Cancel"
Font-Size="Small" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox_bericht" runat="server" Height="98px" ReadOnly="True"
Text='<%# eval("phlb_bericht") %>' TextMode="MultiLine" Width="527px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="phlb_id" SortExpression="phlb_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="phlb_id" runat="server" Text='<%# Bind("phlb_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label_bericht_id" runat="server" Text='<%# Bind("phlb_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#F3F3F3" />
</asp:GridView>
and here is my sqldatasource-object :
<asp:SqlDataSource ID="SqlDataSource_phl_berichten" runat="server" ConnectionString="<%$ ConnectionStrings:ConEP %>"
SelectCommand="sp_berichten_PHL_alle" SelectCommandType="StoredProcedure" UpdateCommand="UPDATE T_bericht_PHL set phlb_bericht = @phlb_bericht where phlb_id = @phlb_id">
<UpdateParameters>
<asp:Parameter Name="phlb_bericht" Type="String" />
<asp:Parameter Name="phlb_id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
It always stay giving the message that you can ' t insert null values in the column " bericht " ... ; All my variables have the same names as the columns in my table. So it is finding the id , but it doesn' t seem to find the value of my edititemtemplatefield "bericht". Hope somebody can give some suggestions on what I can try to do else.
Im looking for example code to make a sql update... I want to use command.Parameters and variables from text boxes and i'm unsure how to do this... Please help. This code below doesn't work but it is an example of what i've been working with.. <code> { string conn = string.Empty; ConnectionStringsSection connectionStringsSection = WebConfigurationManager.GetSection("connectionStrings") as ConnectionStringsSection; if (connectionStringsSection != null) { ConnectionStringSettingsCollection connectStrings = connectionStringsSection.ConnectionStrings; ConnectionStringSettings connString = connectStrings["whowantsConnectionString"]; conn = connString.ConnectionString; using (SqlConnection connection = new SqlConnection(conn)) using (SqlCommand command = new SqlCommand("UPDATE users SET currentscore=5)", connection)) { updateCommand.Parameters.Add("@currentscore", SQLServerDbType.numeric, 18, "currentscore"); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } }</code>
View 3 Replies View RelatedHi All,The following code runs without error but does not update the database. Therefore I must be missing something.I am sure that this a simple task but as newbie to asp.net its got me stumpted. Protected Sub updatePOInfo_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles updatePOInfo.Updating Dim quantity As Integer Dim weight As Integer Dim packed As Integer quantity = CInt(bagsOnPallet.Text) weight = CInt(lbsInBags.SelectedValue) packed = weight * quantity e.Command.Parameters("@packedLbs").Value += packed e.Command.Parameters("@AvailableLbs").Value -= packed End Sub
View 4 Replies View Relatedhi, please someone can help me. I get error 0x80040E14L // The command contained one or more errors. I think that the error is in the sql update command.
this is my code:
HRESULT hr = NOERROR;
IDBCreateCommand * pIDBCrtCmd = NULL;
ICommandText * pICmdText = NULL;
IRowset * pIRowset = NULL;
ICommandPrepare * pICmdPrepare = NULL;
ICommandWithParameters * pICmdWParams = NULL;
ULONG ulNumCols;
IColumnsInfo * pIColumnsInfo = NULL;
LONG lNumCols;
IAccessor * pIAccessor = NULL;
ULONG cParams;
DBPARAMINFO * rgParamInfo = NULL;
OLECHAR * pNamesBuffer = NULL;
ULONG ulNumRowsRetrieved;
HROW hRows[5];
HROW * pRows = &hRows[0];
BYTE * pData = NULL;
DBCOLUMNINFO * pDBColumnInfo = NULL;
WCHAR * pStringsBuffer = NULL;
DBBINDING * prgBinding = NULL;
DBBINDING rgBindings[2];
ULONG cbRowSize;
DBPARAMS params;
HACCESSOR hAccessor;
hr = m_pIDBCreateSession->CreateSession(NULL,IID_IDBCreateCommand,(IUnknown**)&pIDBCrtCmd);
if (FAILED(hr))
goto Exit;
//IID_ICommandWithParameters
hr = pIDBCrtCmd->CreateCommand(NULL,IID_ICommandWithParameters, (IUnknown**)&pICmdWParams);
if (FAILED(hr))
goto Exit;
hr = pICmdWParams->QueryInterface( IID_ICommandText,(void**)&pICmdText);
if (FAILED(hr))
goto Exit;
hr = pICmdWParams->QueryInterface( IID_ICommandPrepare,(void**)&pICmdPrepare);
if (FAILED(hr))
goto Exit;
LPCTSTR wSQLString = OLESTR("UPDATE Pendientes SET Pendiente = ? WHERE IDAnimal = ?");
hr = pICmdText->SetCommandText( DBGUID_DBSQL,wSQLString);
if (FAILED(hr))
goto Exit;
pICmdPrepare->Prepare(1);
if (FAILED(hr))
goto Exit;
pICmdWParams->GetParameterInfo(&cParams, &rgParamInfo, &pNamesBuffer);
hr = pICmdText->QueryInterface( IID_IAccessor, (void**)&pIAccessor);
if (FAILED(hr))
goto Exit;
rgBindings[0].iOrdinal = 1;
rgBindings[0].obStatus = 0;
rgBindings[0].obLength = rgBindings[0].obStatus + sizeof(DBSTATUS);
rgBindings[0].obValue = rgBindings[0].obLength + sizeof(ULONG);
rgBindings[0].pTypeInfo = NULL;
rgBindings[0].pObject = NULL;
rgBindings[0].pBindExt = NULL;
rgBindings[0].dwPart = DBPART_VALUE | DBPART_STATUS | DBPART_LENGTH;
rgBindings[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED;
rgBindings[0].eParamIO = DBPARAMIO_INPUT;
rgBindings[0].cbMaxLen = sizeof(int);
rgBindings[0].dwFlags = 0;
rgBindings[0].wType = DBTYPE_I4;
rgBindings[0].bPrecision = 0;
rgBindings[0].bScale = 0;
rgBindings[1].iOrdinal = 2;
rgBindings[1].obStatus = rgBindings[0].obValue + rgBindings[0].cbMaxLen;;
rgBindings[1].obLength = rgBindings[1].obStatus + sizeof(DBSTATUS);
rgBindings[1].obValue = rgBindings[1].obLength + sizeof(ULONG);
rgBindings[1].pTypeInfo = NULL;
rgBindings[1].pObject = NULL;
rgBindings[1].pBindExt = NULL;
rgBindings[1].dwPart = DBPART_VALUE | DBPART_STATUS | DBPART_LENGTH;
rgBindings[1].dwMemOwner = DBMEMOWNER_CLIENTOWNED;
rgBindings[1].eParamIO = DBPARAMIO_INPUT;
rgBindings[1].cbMaxLen = 8;
rgBindings[1].dwFlags = 0;
rgBindings[1].wType = DBTYPE_I8;
rgBindings[1].bPrecision = 0;
rgBindings[1].bScale = 0;
cbRowSize = rgBindings[1].obValue + rgBindings[1].cbMaxLen;
hr = pIAccessor->CreateAccessor(DBACCESSOR_PARAMETERDATA,2,rgBindings,cbRowSize,&hAccessor,NULL);
if (FAILED(hr))
goto Exit;
pData = (BYTE*) malloc(cbRowSize);
if(!(pData))
{
hr = E_OUTOFMEMORY;
goto Exit;
}
memset(pData,0,cbRowSize);
*(DBSTATUS*)(pData + rgBindings[0].obStatus) = DBSTATUS_S_OK;
*(int*)(pData + rgBindings[0].obValue) = 9;
*(ULONG*)(pData + rgBindings[0].obLength) = 8;
*(DBSTATUS*)(pData + rgBindings[1].obStatus) = DBSTATUS_S_OK;
*(int*)(pData + rgBindings[1].obValue) = 0;
*(ULONG*)(pData + rgBindings[1].obLength) = 4;
params.pData = pData;
params.cParamSets = 1;
params.hAccessor = hAccessor;
hr = pICmdText->Execute(NULL, IID_NULL,¶ms,&lNumCols,NULL);
if (FAILED(hr))
goto Exit;
Exit:...
Hi all,
I have a problem here where I am trying to use SQL Parameters to update a column in the database, but the problem is that I need to concatenate the same column to the SQL parameter. The code I have is below, but it throws a Format Exception...
UPDATE tbl_NSP_Inspection SET Description = Description + @InspectionDescription
...It is because I am trying to Append teh data in the description column to the SQL Parameter (
@InspectionDescription). How do I actually do this using SQL Parameters?
Thanks
Hi, I have a table Projects. This table has ProjectID and Version as PK. The Version starts at 1 and everytime a project is changed, I save the project with the same ProjectID and increase the Version by 1.How can I create a query that get all Projects with the latest Version? Thx
View 1 Replies View RelatedI have a Properties table like thisPropertyID PropertyValue 1 Address 2 City 3 Stateetc.and a UserProfile table like thisUserID PropertyID PropertyValue1 1 123 Main Street1 2 Denveretc.How do I write a query that can populate a registration page with Address,City, State as labels and 123 Main Street, Denver, as TextBox text?
View 4 Replies View RelatedHi,I have included here my webform here.i need some assistance here with code.my webform contains two parts.the 1st part is office info and the 2nd part is client info.i also have two table named office_info and client_info.1st part is populated from the table office_info as soon as the office name is chosen from the dropdownlist.in my scenario,when user selects officename from dropdownlist,then textboxes correspondingto address and email gets populated by the related data from table office_info.2nd part is client info.here there are 3 textboxes(for name,age,address) to collect the data from the client using the form.these data gets posted to new row in table client_info as soon as user clicks on the save button.Now my actual question starts here.when user selects the option from the dropdonwlist the office info displays,now when he fills the client info part and clicks the save button,i want all the data to go to the table client_info in such a way that all the data fromthe client info part plus the id of the office also go along with it.eg: when user clicks the save button.i want data to get submitted in table client_info in this way.(id,name,age,address,off_row_id) (1,jack,25,US,1) here off_row_id is the id from the below table.my table office_info is like this (id,off_name,address,email) eg(1,xyz,ny,xyz@xyz.com) well can anyone tell me how to write query to do insert,edit,update,delete query in this case using c# and sql?here is the scenario <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> Office Info:<br /> <hr /> <br /> Office name: <asp:DropDownList ID="DropDownList1" runat="server" Width="63px"> <asp:ListItem>ABC</asp:ListItem> <asp:ListItem>XYZ</asp:ListItem> </asp:DropDownList><br /> <br /> Address: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <br /> email: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> <br /> <hr /> </div> Client info:<br /> <br /> name: <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /> <br /> age: <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br /> <br /> address:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br /> <br /> <br /> <hr /> <asp:Button ID="Button1" runat="server" Text="save" /> <asp:Button ID="Button2" runat="server" Text="cancel" /> </form></body></html> thanks.jack.
View 8 Replies View Relatedhello everyone. i want to know how asp.net works with sql database. can i have a link to the article where i can perform from basic to advance sql query using asp.net(C#)? (in context of vwd 2005 and sql express ) thanks. jack.
View 1 Replies View RelatedI have two table named tbl_Scale and tbl_NGTrDAMaster
tbl_Scale(ScaleID,ScaleName,ScaleLB,ScaleUB,ScaleSI1,ScaleSI2,ScaleSI3) here scale id is prim key
tbl_NGTrDAMaster(TrDaId,ScaleID,CityTypeID,DAAmount) no prim key
and we get CityTypeID from xml databinder.......
In my form thr is two drop down list one for scale name and another for city type id
this is the data form tbl_NGTrDAMaster
17 1 1 555 18 3 1 777 19 3 1 999 8 1 1 777 5 5 1 34634 20 1 1 52352 27 1 1 6666 23 5 1 12412 12 2 1 235235 13 3 1 456456 14 5 1 1000000 15 4 1 60000 16 5 1 90 24 5 1 25123 25 5 1 13124 26 5 1 12412
but i am expecting only one combination of set.....
like 1-1,1-2,1-3,1-4.......but if reenter 1-1 thn we have to restrict that....
please help me....
i am in big trouble......Thanx in advance
If my qes is not clear for everyone...
plz tell me....
i try my lebel best for understand my prob to u.....
i have a table
tab
col1 col2 num
A a 30
A b 20
B a 10
B b 40
C a 50
C b 40
now i want get col1 by distinct col1 ,and order by num, as the result:
col1
C
B
A
so can someone help me to write this "select..."
Hi
I have 2 tables and I want to Get information from that tables by SQL Query but How Can I writ this SQL Query ? .. My target as Follow
Class Table
-------------------------------------------------
ClassID ClassName
1 AA
2 BB
Student Table
-------------------------------------------------
StudentID StudentName ClassID
1 Student 1 1
2 Student 2 1
3 Student 3 2
4 Student 4 1
5 Student 5 2
6 Student 6 1
How Can I Writ SQL Query to get result like the following ..
--------------------------------------------------
ClassID ClassName StudentCount
1 AA 4
2 BB 2
My SQL Query must get all Class table column plus column content the count of student in each class
And thanks with my regarding
Fraas
Hello,
I have a table with fields; T1: Dept, Name, Desc, ModificationDate
How can I group by T1.Name, T1.Desc and bring T1.Dept which has the latest T1.ModificationDate
Can anyone write me this query?
CUSTOMER
Name City IndustryType
Abernathy Construction Willow B
Amalgamated HousingMernphisB
Manchester LumberManchesterF
Tri-City BuildersMemphis B
ORDERS
NumberCustNameSalespersonNameAmount
100Abernathy ConstructionZenith560
200Abernathy ConstructionJones1800
300Manchester LumberAbel480
400Abernathy ConstructionAbel2500
500Abernathy ConstructionMurphy6000
600Tri-City BuildersAbel700
700Manchester LumberJones150
800 Abernathy Construction Abel 75000
SALESPERSON
NamePercentOfQuotaSalary
Abel63132000
Baker3846200
Jones2649500
Kobad2739600
Murphy4255000
Zenith59129800
I have got the three tables above.
Would you help me to write a SQL query to show the names and PercentOfQuota of sales people who have an order with all cuatomers.
Thank you very much!
CUSTOMER
Name City IndustryType
Abernathy Construction Willow B
Amalgamated HousingMernphisB
Manchester LumberManchesterF
Tri-City BuildersMemphis B
ORDERS
NumberCustNameSalespersonNameAmount
100Abernathy ConstructionZenith560
200Abernathy ConstructionJones1800
300Manchester LumberAbel480
400Abernathy ConstructionAbel2500
500Abernathy ConstructionMurphy6000
600Tri-City BuildersAbel700
700Manchester LumberJones150
800 Abernathy Construction Abel 75000
SALESPERSON
NamePercentOfQuotaSalary
Abel63132000
Baker3846200
Jones2649500
Kobad2739600
Murphy4255000
Zenith59129800
I have got the three tables above.
Would you help me to write a SQL query to show the names and PercentOfQuota of sales people who have an order with all cuatomers.
Thank you very much!
User Page Name Permission
vijay customer.aspx 1
vijay customer.aspx 2
vijay customer.aspx 3
vijay user.aspx 2
Rajashekar customer.aspx 1
Rajashekar customer.aspx 2
Where Permission 1 = SAVE
2 = UPDATE
3 = DELLETE
Where I query on User and PageName I want the output as
User Page Name Permission
vijay customer.aspx 1,2,3
vijay user.aspx 2
Rajashekar customer.aspx 1,2
i am assuming there is a better way to write this query (since im not too proficient in SQL)
sql Code:
Original
- sql Code
select client_id from clients where client_id not in
(select schedule_det.client_id from schedule_det,
schedule_mstr where schedule_det.schedule_id=schedule_mstr.schedule_id
and schedule_mstr.status_code!='COMPLETE')
SELECT client_id FROM clients WHERE client_id NOT IN (SELECT schedule_det.client_id FROM schedule_det, schedule_mstr WHERE schedule_det.schedule_id=schedule_mstr.schedule_id AND schedule_mstr.status_code!='COMPLETE')
ok i have table1, table 2 and table 3.
these table have some common feild names. table1,2 and 3 all have a,b,c and d as field names. each table has other field names too but the ones they all have in common are a,b,c and d.
so i would like to write a query that returns all rows from all 3 tables where column d is greater than 5 and less than 10.
so basically i want it to treat the records from all 3 tables ad one big dataset.
how would i write a query to do this.
i know i could say:
SELECT a,b,c,d
FROM table1,table2,table3
but what gets me is the WHERE clause
do i have to say WHERE table1.d >5 AND table1.d <10 OR table2.d>5 AND table2.d <10 OR table3.d>5 AND table3.d <10
??
any guidance please?
Hello all,
I need a help to write a query. Here is the table
Declare @Test Table
(
EName Varchar(15)
)
Insert into Ename
Select 'a' Union all
Select 'a' Union all
Select 'a' Union all
Select 'b' Union all
Select 'c' Union all
Select 'b' Union all
Select 'd' Union all
Select 'g' Union all
Select 'g'.
Now i need a result like
a0
a1
a2
b0
b1
c0
d0
g0
g1
Could any one can help me to wite this query..?
Thanks
Lakshmi.S
Hi
i want to audit a tables
For That i created audit tables
In that table i want to store data as
all field related to old data table
and from which system user had changed the data
For this system id i used host_id() but the iam not getting the id
Malathi Rao
I have a table with many records in it. There is one field called "Nature". How would I select the value that appears the most often in the "Nature" field? The nature field contains text.
For example, this code selects those with more than 10 records...
I just want the top record.
SELECT count(*) FROM WEBASGN_FULL GROUP BY NATURE HAVING count(*) > 10
Basically select nature from webasgn_full that occurs the most often in the table....
Thanks