declare @NumberToCompareTo int set @NumberToCompareTo = 8 declare @table table ( number int ) insert into @table select 4
[Code] ....
The query selects 4 and 5 of course. Now what I'm looking for is to retrieve the number less or equal to @NumberToCompareTo, I mean the most immediate less number than the parameter. So in this case 5
What I want to have is that every month will sum up the previous month and him self so in the end I will be able the create a graph wuth those numbers:
I have a large query that I am trying to debug in query analyzer.However, the errors I get have no line number or reference to wherethey are failing. How can I find out what line in the query is causinga particular error message to appear?ThanksJohn IveySouth Pike School District
When you get a server error message referring to a line number in ascript, is there an easy way to jump to the correct line? It's noteasy to count down in a big script or when there is a lot of whitespace.In WordPerfect we had a linenum macro that allowed you to enter theline number and it would jump to the line using the same countingmethod as the interpreter that generated the error message. Is theresomething similar with TSQL, or another way?Kerry
What I want to have is that every month will sum up the previous month and him self so in the end I will be able the create a graph wuth those numbers:
i have a huge stored proc which has about 8-9 cursors which move data from a few temp tables to the final tables...and also do lots of calculations in between..
anytime there is an error in the stored proc i have an error page which looks like this
********************** Server Error in '/WebApplication3' Application. --------------------------------------------------------------------------------
a very lengthy page...the numbers are prbly due to the print stmts of the results of some calculations... but my q is..is there any way to return the xact line number where the error occured in the stored proc instead of these infinite list of numbers...its taking pretty long time to go through the entire stored proc to isolate the error...
I am wanting to set up a trigger on our SQL server 2000 to create a sequential order line number in the OrderDetails table for OrderID.
I will be inserting data from an OrderLinesAdd table into the OrderLines table but want the LineNumber field to be incremented by 1 for each group of orders grouped by OrderID that I insert into the table eg.
I have just started using SQL so am not sure how I go about writing the code for the trigger ? It would seem like I will need to use the Max function in the code.
I have a matrix report that shows a certain columns and rows. I need a row counter to show me the amount of rows in that matrix but it doesn't count properly by using the expression: =Int(RowNumber("matrix1") -1) I actually don't have any idea on what this expression should be to fix the row count...to illustrate what I get in the report:
As you can see above, the row count numbers are not lining up at all, it starts at 1, then jumps 2 every count then all of a sudden jumps 5 per line...a pattern that is interesting but difficult to understand. The unique value in this matrix is that serial number but even though i group it by the serial number, it still gives me the funny Row count values.
Hello all Trying to delete some data from a SSCE (2005) DB produces the exception: SqlCeException There was an error parsing the query. [ Token line number = 1,Token line offset = 43,Token in error = C] Here is the code I am using
I'm trying to insert some values into an SQL Compact database on a WM6 device but there is something apparently wrong with my SQL statement...
The program is going to allow users to schedule an SMS message to be sent at a certain date and time. I'm using a database to keep track of the scheduled SMS messages. The database has 3 rows: phone number, message, and the date/time to be sent.
I'm guessing it doesn't like how I am trying to get the data from the different text boxes and the DateTimePicker to go inside the SQL command. Does anyone have any ideas on how to fix my SQL command or how to get data from a textbox and DateTimePicker to be inserted into a database a different way?
Can you help me with SQL issue I€™m stuck on? I wish to take source data that looks like this:
Invoic_num
Line_num
6658
0
6658
2
6658
8
7721
2
7721
3
And rebuild the line numbers like this:
Invoic_num
Line_num
6658
1
6658
2
6658
3
7721
1
7721
2
This seems completely impossible to me. So I was thinking that maybe a second procedure using update could be run against the table after the initial build.
maybe this is not a serious problem, but I tried for days to come toi a solution without success.
My Problem:
I have have several flatfile sources I need to import into a sql-server 2005 DB.
It is very important for me to have the original line number from inside the source file for each record. The rowcount transform doesn't fit in for this task, because it accumulates all rows until the end of the dataflow.
I tried script components and it works fine if i assume there are no errors in my source. then I simply could declare a local variable and count it up and add a custom collumn to my output. But for errors in my source this won't work, because a second script component won't know the actual value of a package level variable, which i use to store the value, because i am only allowed to access this variable in the post execujte method of the script.
Hello everyone, I'm having an issue with dynamically setting the Send Mail task's to field to decent sized recipient list(approx 15 email addys). The strange thing is that this same package works fine if I'm using a list of say 4 email addys. I have double checked everything I can think of....list is seperated by semicolons, each address looks good....and have ran script tasks to check my variables along the path of the package but so far have not found the reason. The error I get is below:
"The specified string is not in the form required for an e-mail address"
Also of note, these addresses are being populated from a table, that is then setting the To string of the send mail task via a seperate variable...that variable being populated from a foreach loop. Again, all of this works fine with a smaller recipient list. Any ideas?
The only thing I can think of right now is to run the send mail task within the foreach loop...but then I'll be sending a seperate email for each address and would like to avoid that if possible.
ID                      Customer              Type                 TypeNUm 100                     Tiger                    Item                   T100  100                      Tiger                    Item                   T200 100                     Tiger                    Item                   T300 100                     Tiger                    Shiper                  SAAA 100                      Tiger                   PO                      POAAA 200                      Panera                 GL                  WE 200                      Panera                 PO                  POBBB
The reftypes are not always the same, what I need is to get it in this form
ID                      Customer              Type             TypeNUm 100                     Tiger                    Item                   T100,T200, T300 100                     Tiger                    Shiper                  SAAA 100                      Tiger                   PO                      POAAA 200                      Panera                 GL                     WE 200                      Panera                 PO                    POBBB
How to summarise the data in this table to a single row output per site (2 records for every SiteID). I am based in the UK so the data copied from SQL is in the US format. I can convert this to UK date without any issues.
CREATE TABLE [dbo].[MRMReadings]( [SiteIncomeID] [int] IDENTITY(1,1) NOT NULL, [SiteID] [nchar](5) NOT NULL,
[Code] ....    Â
Is it possible to return the data in the following format merging 2 lines of data into one output:
 SiteID  ReadStartDate ReadEndDate    ReadStartIncome    ReadEndIncome L0020    19/05/2015 05:00 20/05/2015 05:00   85.98    145.98 L0101    19/05/2015 22:07   20/05/2015 22:14         1,936.08      1,438.89 L0102    20/05/2015 21:16   19/05/2015 21:48  143.65 243.5
I need to group by transactions at line item level. As the each item in the transaction may belong to different category and I'musing case statement to identify particular category for one column , I'm using sub-query to retrieve the results at item level.
SELECT Â Â Â Â Â Â Â Â Â ID1, Â Â Â Â Â Â Â Â Â ID2, Â Â Â Â Â Â Â Â Â Â type, Â Â Â Â Â Â Â Â Â (case when type = '1' then sum(value) else '0' end) as Value1, Â Â Â Â Â Â Â Â Â (case when type = '3' then sum(value) else '0' end) as Value2, Â Â Â Â Â Â Â Â Â Â (case when type <> '1' and type <> '3' then sum(value) else '0' end) as Value3 FROM table1 WHEREÂ ID1 = 'x' and ID2= 'y'Â GROUP BY ID1, ID2, Type
Which returns: ID1    ID2       Type    Value1    Value2    Value3 005   11547   0         0.00        0.00       279.23 005   11547   1         15.23      0.00       0.00 005   11547   3         0.00        245.50    0.00
And I want to obtain this result: ID1Â Â Â Â ID2Â Â Â Â Â Â Â Value1 Â Â Â Value2 Â Â Â Value3 005Â Â Â 11547Â Â Â Â 15.23Â Â Â Â Â Â 245.50Â Â Â Â 279.23
How to launch Oracle SQL Developer through "Run"Â window in windows as we can launch SQL Server Management studio through "Run" command line using command line "sqlwb -S localhost -d MyDB -U sa -P
I am trying to use FOR XML under SQL Server 2014 to write out a large XML data set. I want it to look like
<CVS_Member_Add_Change> Â Â <RecordType>3</RecordType> Â Â <Carrier>1266</Carrier> Â Â <MultiBirthCode>0000000</MultiBirthCode> Â Â <MemberType></MemberType>
[Code] ....
That's how it looks when you click on the results of a small subset of the query. Â Just what I want. Â Unfortunately when you try to right click and save it you getÂ
I have a query that returns the data about test cases. Â Each test case can have multiple bugs associated to it. Â I would like a query that only returns the test cases that have all their associated bugs status = closed.For instance here is a sample of my data
TestCaseID TestCaseDescription  BugID BugStatus 1         TestCase1            1    Closed 2         TestCase1            2    Open 3         TestCase2            11   Closed 4         TestCase2            12   Closed 5         TestCase2            13   Closed
How can I limit this to only return TestCase2 data since all of that test case's bugs have a status of closed.
ID  Item           RandomNumber ------------------------------------------- 1   JEANS                   1234567 2   SHIRT                 72813550 3   HOOD                           Null 4   TROUSER             72191839 5   BLAZER                            0
I want to perform a query so that SQL should look for RandomNumber Values and set a Unique Random Number Where RandomNumber Value is Null or 0.So I have got a solution as one of the MSDN Member shared the below query
select id,item,RandomNumber=Case when RandomNumber=0 then (select floor(rand()*100000000-1)) when RandomNumber is null then (select floor(rand()*100000000-1)) else RandomNumber end from tblProducts
So, can you all confirm me, that performing this query ensures that if a Value is assigned to one of the Item in RandomNumber Column, that value will not be assignend to any other Item in RandoNumberColumn.
I am currently working on an app and have an issue with a table in the database. Â The table has 10,000 records in it and a column is added that is to use a 4 digit in sequence. The datatype for the new column is varchar since no math will ever be done on the added column. Â If necessary, I can change the datatype but would prefer not to. Â The 4 digit would start with 0000 at ID 1 and go to 9999 at ID 10000. Â I'm thinking some type of update statement since it is updating each record but how would it be done sequentially?
I have a Users Table. It is full of users already and I would like to start using the UserPIN in the software (this is an nvarchar column).
I would like to update the UserPIN column with the row_number. All of my efforts have resulted in setting the UserPIN to 1 for every record. Â I just want an update query that fill the UserPIN column in sequential order.
I have a SELECT statement with multiple JOINs. I want to number the rows returned by this SELECT statement. What's the easiest way to do this?
My current SELECT statement returns this:
ProjectId -- TaskId -- TaskName 123 Â - 111 -- Do something 123 Â - 222 -- Do something else 123 Â - 333 -- Do one more thing
I want to return this:
ProjectId -- TaskId -- TaskName -- Sequence 123  - 111 -- Do something  -- 1 123  - 222 -- Do something else  -- 2 123  - 333 -- Do one more thing  -- 3
How can I add a group number to the following query?
For example, I want to be able to have all rows that have Category = 'Field Sales' and Division = 'CA BDM' to be given a unique group number (GN):
RN          ReportDate Category            Division            TotalBalance -------------------- ---------- ------------------------------ ------------------------------ --------------------- 1           2015-06-08 Field Sales           CA BDM             299743154.3912 2           2015-06-07 Field Sales           CA BDM             299765954.0354 3           2015-06-01 Field Sales           CA BDM             297902654.4172 1           2015-06-08 Key Accounts          Life Office           49954981.74 2           2015-06-07 Key Accounts          Life Office           50016989.22 3           2015-06-01 Key Accounts          Life Office           50169967.26 4           2015-05-31 Key Accounts          Life Office           50169918.01
Becomes
GN  RN          ReportDate Category            Division         TotalBalance -------------------------- ---------- ------------------------------ ------------------------------ --------------------- 1    1           2015-06-08 Field Sales           CA BDM           299743154.3912 1    2           2015-06-07 Field Sales           CA BDM           299765954.0354 1    3           2015-06-01 Field Sales           CA BDM           297902654.4172 2    1           2015-06-08 Key Accounts          Life Office           49954981.74 2    2           2015-06-07 Key Accounts          Life Office           50016989.22 2    3           2015-06-01 Key Accounts          Life Office           50169967.26 2    4           2015-05-31 Key Accounts          Life Office           50169918.01
i.e. each combination of Category+Division results in a new GN.
The query is:
selectROW_NUMBER() over (partition by Category, Division order by ReportDate desc) 'RN' , ReportDate , Category , Division , sum(BalanceGBP) as 'TotalBalance' FROM FlowsAndOpenings group by ReportDate, Category, Division order by Category, Division, RN
I have a table which has 2 columns and the data is like below
API_Number       Group_Name
1234Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group A 3241Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group A 1234Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group B 4567Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group C 7896Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group D 3241Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group E
 I wanted to find the API numbers which are repeating in different groups. In the output I want
 API_Number          Group_Name
1234Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group A,Group B 3241Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Group A,Group E
What I would like to do is to have a TSQL Select return the number of records in the Result as if TOP (n) had not been used. Example:I have a table called Orders containing more than 1.000 records with OrderDate = '2015/07/21' and my client application has a threshold for returning records at 100Â Â and therefore the TSQL would look like
SELECT TOP (100) *Â FROM Orders Where OrderDate = '2015/07/21'Â ORDER by OrderTime Desc
Now I would like to "tell" the client that only 100Â of 1.000 records are shown in the client application grid. Is there a way to return a value indicating that if TOP (100) had not been used the resultset would have been 1.000. I know I could create the same TSQL using COUNT() (SELECTÂ COUNT(*)Â FROM Orders Where OrderDate = '2015/07/21'Â ORDER by OrderTime Desc) and return that in a variable in the SELECT statement or even creating the COUNT() as a subquery and return it as a column, but I would like to avoid running multiple TSQL's. Since SQL Server already needs to select the entire recordset and sort it (ORDER BY) and return only the first 100 the total number of records in the initial snapshot must somehow be available.
I need to update many rows in some table. Â I've made such SQL query:
UPDATE [%TableName%] SET [%FieldName%] = CASE Â Â Â Â Â Â Â Â Â Â Â WHEN ID = 1Â THEN '1' Â Â Â Â Â Â Â Â Â Â Â WHEN ID =2Â THEN '2' Â Â Â Â Â Â Â Â Â Â Â .... Â Â Â Â Â Â END; Â Â Â Â Â Â [%FieldName2%] = CASE Â Â Â Â Â Â Â Â Â Â Â WHEN ID = 1Â THEN '1' Â Â Â Â Â Â Â Â Â Â Â WHEN ID = 2Â THEN '2' Â Â Â Â Â Â Â Â Â Â Â .... Â Â Â Â Â Â END; WHERE ID IN {1, 2, ...}
Are there some limitations for CASE operator? How many "when - then" conditions can I include in query?