Compound Statements

Jul 20, 2005

Hello,

How can I stop/prevent SQL server from running compound SQL
statements. I do not want the server to run multiple
update/delete/insert/select statements as a batch. Is there an option?

/Kaf
www.afiouni.com

View 11 Replies


ADVERTISEMENT

Compound Primary Key - How To ?

Nov 25, 2003

I need to know how to create a compound primary key in Transact-SQL
It's really simple, it's a table with 3 column, two of those make the primary key Right now the CREATE TABLE look like this:/* SectionsContent Table */
CREATE TABLE SectionsContent (
SectionID Int NOT NULL
CONSTRAINT FK_SectionsContent_SectionID FOREIGN KEY
REFERENCES PsychoCMS.dbo.Sections(ID),
DocumentID Int NOT NULL
CONSTRAINT FK_SectionsContent_DocumentID FOREIGN KEY
REFERENCES PsychoCMS.dbo.Documents(ID),
Position int NOT NULL
)

Can anyone help me ?

View 1 Replies View Related

Utilizing Compound Indexes

Jul 23, 2005

Is it possible to force the use of a compound index in a query?create table Test (ColOne int, ColTwo int)The compound index is ColOne + ColTwo.I'm interested in searching on ColTwo, but I also know the value ofColOne will always be the number "1".How do you structure the SQL statement to concatenate the two INTs anduse the index? Note that I don't have any control over the creation ofthese indexes.

View 3 Replies View Related

Confused Exec With A Compound Sql String

Aug 1, 2000

I am trying to make up a SQL string which will be executed with the Exec command

I want to add a return column that is not in the table, and the table columns:

something like
Select @Ten As Ten, @Tablename.* From @Tablename (
where @Ten has an integer value. )
The statement was originally:
select @SQL = 'select * from ' + @TempName
exec (@SQL)
which had no problem. Then I needed to add an extra column of static data to all the returned rows, and confusion !!!!!

Thanks,
Judith

View 1 Replies View Related

Generating Values As Part Of A Compound Key

Aug 30, 2005

BEGINNER QUESTIONI have a table which has a compound primary key consisting of two columns.One of these columns is a foreign key which is generated in another table byan identity.I want to be able to generate the other primary key column valueautomatically when an insert occurs but assume that I cannot use an identitybecause it would have to be unique for this table.There will be potentially more than one user accessing this table so I wantto avoid generating the key on the client side.How can I do this? Will it require some hardcore T-SQL?I hope this is clear (I suspect it isn't) I'd be happy to supply more info.I would be extremely grateful for any help!Mark.

View 4 Replies View Related

Compound Primary Key - Order Not As Expected

Apr 26, 2006

Hello,if you create this table:create table hello (int a, int bconstraint pk_hello primary key clustered ( a, b ))and then insert the following recordsa,b1,11,21,32,12,22,33,13,23,3and then doselect a,b from hellothe output seems to be:a,b1,12,13,11,22,23,21,32,33,3which is wrong and (i think) is reflecting the actual index orderand physical order on diskit should be:a,b1,11,21,32,12,22,33,13,23,3i have tested this on a table with 500,000 recordsand sure enough if you declare the clustered primary key fields inreverse order:constraint pk_hello primary key clustered ( b, a )two things happen:- the select with no order by returns the records in the expected order- queries relying on that order run MUCH FASTERhas anyone else seen / noticed this?

View 9 Replies View Related

Compound Return On A Rolling Daily Basis

Nov 2, 2014

Looking to create a query, as simple as possible, that allows me to compound returns on a rolling daily basis. So far this this have I have:

DECLARE @stock_returns TABLE
(
stock_code VARCHAR(10) NOT NULL,
date1 DATE NOT NULL,
daily_return NUMERIC(10, 2) NOT NULL
);

[Code] ....

But I´m not getting what I need. If you run the above select, the output should be:

stock_codedate1daily_returnLAGCompound_return
stock12014-07-080.00510 0.00000 0.0051000000
stock12014-07-090.00300 0.00510 0.0081153000
stock12014-07-100.00500 0.00300 0.0080150000
stock12014-07-110.00600 0.00500 0.0110300000
stock12014-07-120.00200 0.00600 0.0080120000
stock12014-07-130.00700 0.00200 0.0090140000
stock12014-07-140.00240 0.00700 0.0094168000
stock12014-07-150.00240 0.00240 0.0048057600
stock12014-07-160.00250 0.00240 0.0049060000

The problem is with this column:

(lag(daily_return, 1, 0) over (order by date1) + 1) * (daily_return + 1) - 1 as Compound_return

The (daily_return + 1) portion should be the accumulated compound return. So it should be something like

(lag(ACCUMULATED_COMPOUND RETURN, 1, 0) over (order by date1) + 1) * (daily_return + 1) - 1 as Compound_return

And the output should be:

Date1Daily returnLAGCompound Return
08/07/20140,00510,00000,0051
09/07/20140,00300,00510,0081
10/07/20140,00500,00300,0132
11/07/20140,00600,00500,0192
12/07/20140,00200,00600,0213
13/07/20140,00700,00200,0284
14/07/20140,00240,00700,0309
15/07/20140,00240,00240,0334
16/07/20140,00250,00240,0359

View 10 Replies View Related

Full Text Catalog, Compound Key Problem

Dec 19, 2007

Hi

I have a sql 2000 db which has a table that has a compound key, the problem is that I would like to create a Full Text Catalog for this table. However I noticed that i need a single primary key... but I dont have one.

I created another field on my table called "ftcID" as an int with identity set to Yes

However when I try and create a catalog it doesnt detect that this field is unique.

Does my unique field have to be a Primary Key, I cant remove the compound primary key as it will break my application.

Any help would be much appreciated

Many thanks in advance

View 3 Replies View Related

Passing Compound Primary Key Values To A Stored Procedure Using ADO.NET

Apr 10, 2008

Hi all,
I've had this problem for a while now and I'm looking for a better solution.


I'm pulling through a dataset from a SQL Server 2005 database and populating it into a DataGridView. The end user updates information on the grid and I then want to updates the results in the SQL Server table. My table has a compound primary key made up of two fields.


I'm currently looping through the data grid and for each value identified to update I'm executing a stored procedure that takes the two fields as parameters. However I know that this method isn't very efficient, especially if the user wants to update a few hundred records as it will execute the stored procedure a few hundred times.


Is there a way I can pass the two parameters in an ArrayList or something like that? I need SQL Server to be able to take the parameter. Is XML the way to go or is there any additional support in the .NET framework for such problems?


Thanks for your help.

View 7 Replies View Related

SSIS SCD Type I, Dim Table Compound Key Selection For Business Key

Apr 28, 2006

Hai,

I have been working in DW for a while, but using SSIS as an ETL tool is new for me. I worked extensively on Informatica.

Coming to my question, right now I am trying to do SCD type 1. But my dimension table has a compound key. i.e more than 1 column makes a key for the table. But SCD wizard allows to select only 1 attribute as a business key. Does any one have any suggestions on how to implement SCD if the target table has compound key.

Thanks in advance for your suggestions and answers.

Venkat

View 5 Replies View Related

SQL Statements

Aug 17, 2006

Hi guys,
Need some help in some query processing...
Here goes,this is the results i have obtained so far
|id |cat | name |
1 .....a... apple
1 .....b .. banana
2 .....a ...austria
2 .....b ...brazil
2 .....c ...china
3 .....a ...abraham
3 .....c ...clinton

Column cat can have at most 3 different types of values..{a,b,c}

I wanna write a query such that the result comes out as such
<(....id ......a .......b......... c..) corresponding to these fields.>

|Col 1| Col 2 | Col 3 | Col 4|
....1 ...apple ...banana
....2 ...austria .brazil... china
....3 ...abraham ..........clinton

Anyone can help...thanks guys

View 1 Replies View Related

If Statements In SP

Sep 21, 2006

I use SQL Server 2005.I want to create a SP "Search". With this function a user can serach the member database on several criteria: age minimal, age maximal, name, city..BUT these criteria do not necessarily have to be defined by the user, so it might be that a user searches for all members whose age is between ageMin and ageMax leaving the name and city criteria empty.So in my SP I have to check whether these values are empty or not. If a parameter is not empty I have to add it to my selection query.. BUT, I know that SQL Server makes an execution plan, and understood that when you use if-statements the procedure needs to be recompiled every time?Is this true? If so:how does this work then?Is there another way for me to still be able to create this SP?

View 2 Replies View Related

Help With If-Else Statements In SQL...please...

Dec 11, 2006

Hello guys. How is this declared in SQL?
Select * FROM my_table
     if my_column = "1" UPDATE my_table SET  my_other_column= "a"       ////my_column and my_other_column belong to my_table
     else if my_column="2" UPDATE my_table SET  my_other_column= "b" ////my_column and my_other_column belong to my_table
   

View 4 Replies View Related

Sql Statements Per Second

Jan 27, 2008

Hi, I would like to know the number of SQL statements per second being generated by my web site. How can I know this?  Best Regards,MeeNge  

View 6 Replies View Related

If Statements

Apr 8, 2008

 Hello I have an SQL Data Source  i want to compare 2 dates if one is equal to or less than the other i want to return either a string or a true i have been trying combinations for about an hour and it's getting a little frustrating i;ve tried searching for an example but cant find one so somesthing like Select ValuesWhere Date1 <= Date2 Return "String"(orTrue?) also IF date1 <= Today() Return "String OR True" thanks Chris 

View 3 Replies View Related

Sql If Statements

Feb 22, 2006

I have some trade data. One colum is tran_status_mtf. within that column is "settled/traded", "cancelled", and "revised". I want to write and SQL statement that says if the trade is "settled" or "traded" display "A" in my output. How do I do this? I am new to SQL. Thanks in advance guys!!!

View 14 Replies View Related

IF Then Statements

Jun 3, 2008

I need to create a brief statement in Design View for SQL 2000.

I successfully wrote "isnull(dbo.Data.Parcel,'')in the Column in Design View, which would ensure that a null value would be listed as a blank. Now I need to have dbo.data.status show as 'C&G' in any instance of data, otherwise it will be listed as blank. I tried writing "isnotnull(db0.data.status,'Homestead', '')", but it does not work.

Is there a simple statement I can write in "column" of design view that can get the results that I need?

-Steve

View 4 Replies View Related

Using Sum In Sql Statements

May 21, 2007

I have written an sql statement thats using sum. The problem that I have is that when the value is zero it returns Null. Is there a way that I could return zero instead of null.

View 5 Replies View Related

SQL If Statements

Oct 19, 2007



I am totally new to creating IF statements inside stored procedures. I am passing some parameters from a ColdFusion form to a SP and if the form is empty for the small date I get an error. I would like to be able to check in the procedure to see if the parameter is empty and if it is set a default value for it. Here is my code.
@JOB1,
@COLLEGEDATE smalldatetime,
If(@COLLEGEDATE <> ''")
@COLLEGEDATE smalldatetime,
ELSE
@COLLEGEDATE = getDate(),
RETURN
@JOB2

View 3 Replies View Related

Different T-SQL Statements?

Sep 16, 2006

Hi, i just want to know if the T-SQL statements in SQL server 2005 are different from SQL Server 2000???

If they are different, where can i find the Server 2005 T-SQL Statements?

View 6 Replies View Related

SUM And Iif Statements

Apr 16, 2007

Hello,



I have a report with 1 field that I need to sum into 2 different textboxes based on another field's value.



Specifically, Is it simply doing something like this below?



=Iif(Fields!iBB.Value=1, Sum(Fields!Billed.Value)

=Iif(Fields!iBB.Value=0, Sum(Fields!UnBilled.Value)



Which will not get past intellisense checking, -or- do I have to do something different here?



Thanks in advance.

View 10 Replies View Related

Help With Insert Sql Statements...

Dec 15, 2006

Hi guys! I have these commands that insert into two tables, if condition 1 is met, it will insert into the first table, if the second condition is met, it will insert into the second table.
Is there a way for the insert statements to be merged so that I won't be executing two statements? 
Dim update_phase_before As New SqlCommand("INSERT INTO TE_shounin_todokesho_jizen (syain_No,date_kyou,time_kyou) SELECT syain_No,date_kyou,time_kyou FROM TE_todokesho WHERE TE_todokesho.b_a='before'", cnn)
Dim update_phase_after As New SqlCommand("INSERT INTO TE_shounin_todokesho_jigo   (syain_No,date_kyou,time_kyou) SELECT syain_No,date_kyou,time_kyou FROM TE_todokesho WHERE TE_todokesho.b_a='after'", cnn)     
 
Thanks.

View 1 Replies View Related

Several Select Statements?

Jan 16, 2007

Hello, how can i merge together several select statements?
I have something like this:
CREATE PROCEDURE Forum_GetThreads @ID int,@AscDesc bitASBEGINSET NOCOUNT ON;SELECT * FROM forum_ansageSELECT * FROM forum_topics WHERE (status = 0) ORDER BY (created) DESCIF (@AscDesc = 0)BEGIN      SELECT * FROM forum_topics WHERE (status > 0) ORDER BY (created) DESCENDELSEBEGIN      SELECT * FROM forum_topics WHERE (status > 0) ORDER BY (created) ASCENDHere i want to merge them all together and return only one SELECT statement with all the data

View 5 Replies View Related

Max SQL Statements In One Page

Feb 21, 2007

I'm running a custom built report on .net page  Basically there are a lot categories.  I need to run SQL statements for and for each category, the catch is these statements are all in loops for i = 1 to 12.  Therefore 108 categories X 12 iterations of SQL calls =  a little more that 1200 sql calls from one .net page. 
 There is obviously a major problem with load time and running these reports are painful to the user and the system.
 
Is there any easier way to possibly pre-compile all the data into a temp database so I wouldn't need to make as many sql calls???????  If so, would a stored procedure handle something like this.
 Sorry for being somewhat vague.

View 7 Replies View Related

Apostrophes, Etc. In WHERE Statements?

Apr 11, 2007

How do I handle and apostrophes and other punctuation in stored procedure Sql statements:
SELECT        L_ID, L_NameFROM            tblHVACContractorsWHERE        (L_Name = 'Mare's Heating & Cooling Services')

View 5 Replies View Related

Use Two SQL Statements In One SqlDataSource ?

May 4, 2007

Hello,
I have SqlDataSource to retrieve a data into DetailsView, or GridView, whatever.
I want to use two Select command like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=AHMED-4714D04B3;Initial Catalog=mp;Integrated Security=True"
<%
if (( parID == 3) || (ParID ==4)
{
SelectCommand="SELECT [PID], [PageID], [PageContent], [ParID], [ChiID] FROM [mp_page] WHERE ([ParID] = @ParID)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ParID" PropertyName="SelectedValue" />
</SelectParameters>
}
else
{
 
SelectCommand="SELECT [PID], [PageID], [PageContent], [ParID], [ChiID] FROM [mp_page] WHERE ([ChiID] = @ChiID)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ChiID" PropertyName="SelectedValue" />
</SelectParameters>
}
</asp:SqlDataSource>
Is it possible to do something like that ?

View 3 Replies View Related

Help Writing SQL Statements

Jun 5, 2008

Hey everyone,
  I'm making a site and I need to write some code that will do the following things: 


Write a statement for the Page_Load event to pull the information from the db and load it into a textbox and a textbox with multiline attribute.

View 13 Replies View Related

Help With Combining Sql Statements

Mar 7, 2006

I'm trying to combine the following two strings to create a single Insert statement (and thus only generate one record instead of two).
insertString = "Insert comments (uID) Select uID FROM users WHERE uName = @uName"
insertString2 = "INSERT comments (eventID, text) VALUES ( @eventID, @comment)"
I have tried:
Insert comments (uID, eventID, text) SELECT uID FROM users WHERE uName  = @uName VALUES (uID, @eventID, @comment)
Individually they work fine, but I can't get the syntax correct to allow them to work together. As you can tell, I'm not very good with SQL, so any help would be greatly appreciated!
Thanks in advance.

View 2 Replies View Related

Concatenating Sql Statements

Jan 30, 2002

I have a web application that has SQL7 as the back end. SQLServer and ORACLE have a feature that allows sql commands to be combined in one statement. Another words I am able to to

SELECT * FROM table_name WHERE id = 2 DROP TABLE other_table

If I type this in a query analyzer It will perform both commands. Is there a way to turn this 'feature' off.

The main reason I want to turn it off is so if a numerical value is sent as a url variable someone can't add the drop table statement or any other sql command to the value of the url variable and have it executed. We have added ample code to trap for this problem but I would like to also handle it at the database level.

Thanks,
Jeff

View 2 Replies View Related

HELP....&#34;OR&#34; Conditions In SQL Statements

May 31, 2000

Folks,

I'm having some real problems using the OR condition in a very simple SQL statement and could use your help or insight on where the problem lies, or perhaps a workaround.

I have a large flat table in a SQL 7 database with 10 million + records called "HISTORY". I have not installed either service pack 1 or 2. I'm attempting to run a query that references the following four fields which are all non-clustered keys:

EQUIPMENT_NO TEXT 12
CHASSIS_IN TEXT 12
CHASSIS TEXT 12
SVC_DATE_TIME SMALLDATETIME

Here's the SQL statement:

SELECT * FROM HISTORY WHERE (HISTORY.EQUIPMENT_NO = 'XYZ123' OR HISTORY.CHASSIS = 'XYZ123' OR HISTORY.CHASSIS_IN = 'XYZ123') AND SVC_DATE_TIME >= '01/15/00 00:00:00 AM' AND SVC_DATE_TIME <= '02/28/00 23:59:59 PM'
ORDER BY EQUIPMENT_NO

This query takes 11 min. 5 sec. inder the Query Analyzer and ultimately returns the 31 desired records.

If you remove the SVC_DATE_TIME criteria, about 350 records are returned in a matter of seconds. I've also tried variations on the date syntax such as '01/15/00', etc. with no change in the amount of time to execute.

Other queries such as a simple AND condition combining EQUIPMENT_NO and SVC_DATE_TIME are snappy.

Are there known problems/bugs with "OR" conditions in queries that anyone is aware of, particularly with parentheses; am I composing this query incorrectly? Is there some alternate syntax that would work as expected? I can't see where the query shouldn't execute quickly as expected, particularly with all indexed fields involved. I'm stumped! Lend me your expertise. Thanks much.

Clark R. Farabaugh, Jr.
Financial Systems Analyst
VIT
Norfolk, VA

View 8 Replies View Related

Building Sql Statements

Jan 6, 2003

Hi,

I am having some problems trying to build an sql statement from more than one statement.

Here is the statement

select 'Insert App_Column (Table_ID, Column_Type_Transformation, Column_Name, )
Values (@table_ID,' ,'NULL,', name from payatwork..syscolumns where id in (
select id from payatwork..sysobjects where name like 'Employee_Profile')
order by colorder, ')'

What I am finding is that the bracket at the end of the statement is not appearing - how do I append statements to the end of this sql statement (i've tried various combinations of the + sign and the comma without success.

thanks,

Jim

View 4 Replies View Related

Update Statements

Apr 26, 2004

How to update a column in the table using the data from another column in the same table? Thanks.

View 1 Replies View Related

Concatenating Sql Statements

Jan 30, 2002

I have a web application that has SQL7 as the back end. SQLServer and ORACLE have a feature that allows sql commands to be combined in one statement. Another words I am able to to

SELECT * FROM table_name WHERE id = 2 DROP TABLE other_table

If I type this in a query analyzer It will perform both commands. Is there a way to turn this 'feature' off.

The main reason I want to turn it off is so if a numerical value is sent as a url variable someone can't add the drop table statement or any other sql command to the value of the url variable and have it executed. We have added ample code to trap for this problem but I would like to also handle it at the database level.

Thanks,
Jeff

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved