Help How To Create A Row Progressive..
Jul 20, 2005
Hi to everybody, I'd like to know how to extract a progressive number in a
select.
Example..
Select * from employers
Name Surname Position Age Hire Date Progressive
Mario Rossi Consultant 25 26/07/2003 1 (this
field doeas not exists in table)
fredrick Bauman Secretary 30 15/06/1999 2
Liana Orfei Director 45 15/01/1970 3
.................................................. ...........................
..............n
Thanks to every body
View 5 Replies
ADVERTISEMENT
Nov 23, 2007
Trying to return actual values that will look at dates after it and return the total actuals for week 1, week 1 and 2, week 1, 2 and 3, etc. Here is a sample of data that is in a table:
CREATE TABLE #tmpactuals
(caid int IDENTITY(1,1) NOT NULL,
prediciton_date_startdate datetime NULL,
prediction_date_enddate datetime NULL,
actuals money NULL
) ON [PRIMARY]
INSERT into #tmpactuals VALUES('4/22/2007 0:00', '4/28/2007 0:00', 193113)
INSERT into #tmpactuals VALUES('4/29/2007 0:00', '5/5/2007 0:00', 153320)
INSERT into #tmpactuals VALUES('5/6/2007 0:00', '5/12/2007 0:00', 122271)
INSERT into #tmpactuals VALUES('5/13/2007 0:00', '5/19/2007 0:00', 80846)
INSERT into #tmpactuals VALUES('5/20/2007 0:00', '5/26/2007 0:00', 110603)
INSERT into #tmpactuals VALUES('5/27/2007 0:00', '6/2/2007 0:00', 89748)
INSERT into #tmpactuals VALUES('6/3/2007 0:00', '6/9/2007 0:00', 116675)
INSERT into #tmpactuals VALUES('6/10/2007 0:00', '6/16/2007 0:00', 140567)
INSERT into #tmpactuals VALUES('6/17/2007 0:00', '6/23/2007 0:00', 555827)
INSERT into #tmpactuals VALUES('6/24/2007 0:00', '6/30/2007 0:00', 119377)
INSERT into #tmpactuals VALUES('7/1/2007 0:00', '7/7/2007 0:00', 73529)
INSERT into #tmpactuals VALUES('7/8/2007 0:00', '7/14/2007 0:00', 101982)
INSERT into #tmpactuals VALUES('7/15/2007 0:00', '7/21/2007 0:00', 129099)
INSERT into #tmpactuals VALUES('7/22/2007 0:00', '7/28/2007 0:00', 178279)
INSERT into #tmpactuals VALUES('7/29/2007 0:00', '8/4/2007 0:00', 178279)
Again, what I want to return is for each prediction_date_enddate is the total actuals for that date plus the running totals for the next 13 weeks. So for the first date you would have the actuals for that week. Prediction week two you would have the actuals for that week plus the next week, etc. Want to do this for each end date. The results should look something like this: (Well not exactly like this. I transposed the info for readability on the post. Obviously it would be the columns with 2 rows of data based on the test data)
Columns: Row 1, Row 2
prediction_date_enddate 4/28/2007 0:00, 5/5/2007 0:00
Prediction Week 1: 74140, 123535
Actuals Week 1: 193113, 153320
Difference Week 1: 118973, 29785
Percent Week 1: 260%, 124%
Prediction Week 2: 237762, 245906
Actuals Week 2: 346433, 275591
Difference Week 2: 108671, 29685
Percent Week 2: 146%, 112%
Prediction Week 3: 413159, 517435
Actuals Week 3: 468704, 356437
Difference Week 3: 55545, -160998
Percent Week 3: 113%, 69%
Prediction Week 4: 691786, 738029
Actuals Week 4: 549550, 467040
Difference Week 4: -142236, -270989
Percent Week 4: 79%, 63%
Prediction Week 5: 911249, 846405
Actuals Week 5: 660153, 556788
Difference Week 5: -251096, -289617
Percent Week 5: 72%, 66%
Prediction Week 6: 989056, 939253
Actuals Week 6: 749901, 673463
Difference Week 6: -239155, -265790
Percent Week 6: 76%, 72%
Prediction Week 7: 1089510, 1056769
Actuals Week 7: 866576, 814030
Difference Week 7: -222934, -242739
Percent Week 7: 80%, 77%
Prediction Week 8: 1191440, 1151155
Actuals Week 8: 1007143, 1369857
Difference Week 8: -184297, 218702
Percent Week 8: 85%, 119%
Prediction Week 9: 1292520, 1383868
Actuals Week 9: 1562970, 1489234
Difference Week 9: 270450, 105366
Percent Week 9: 121%, 108%
Prediction Week 10: 1534959, 1505965
Actuals Week 10: 1682347, 1562763
Difference Week 10: 147388, 56798
Percent Week 10: 110%, 104%
Prediction Week 11: 1677370, 1683000
Actuals Week 11: 1755876, 1664745
Difference Week 11: 78506, -18255
Percent Week 11: 105%, 99%
Prediction Week 12: 1872707, 1895996
Actuals Week 12: 1857858, 1793844
Difference Week 12: -14849, -102152
Percent Week 12: 99%, 95%
Prediction Week 13: 2299290, 2108978
Actuals Week 13: 1986957, 1972123
Difference Week 13: -312333, -136855
Percent Week 13: 86%, 94%
View 6 Replies
View Related
Aug 4, 2004
Hi All,
I'm trying to create a proc for granting permission for developer, but I tried many times, still couldn't get successful, someone can help me? The original statement is:
Create PROC dbo.GrantPermission
@user1 varchar(50)
as
Grant create table to @user1
go
Grant create view to @user1
go
Grant create Procedure to @user1
Go
Thanks Guys.
View 14 Replies
View Related
May 20, 2008
the subject pretty much says it all, I want to be able to do the following in in VB.net code):
{[If [table with this name] already exists [in this sql database] then [ don't create another one] else [create it and populate it with these values]}
How would I do this?
View 3 Replies
View Related
Mar 3, 2014
I created a cursor that moves through a table to retrieve a user's name.When I open this cursor, I create a variable to store the fetched name to use within the BEGIN/END statements to create a login, user, and role.
I'm getting an 'incorrect syntax' error at the variable. For example ..
CREATE LOGIN @NAME WITH PASSWORD 'password'
I've done a bit of research online and found that you cannot use variables to create logins and the like. One person suggested a stored procedure or dynamic SQL, whereas another pointed out that you shouldn't use a stored procedure and dynamic SQL is best.
View 3 Replies
View Related
Jul 20, 2005
Can I dynamically (from a stored procedure) generatea create table script of all tables in a given database (with defaults etc)a create view script of all viewsa create function script of all functionsa create index script of all indexes.(The result will be 4 scripts)Arno de Jong,The Netherlands.
View 1 Replies
View Related
Jul 20, 2005
I have some code that dynamically creates a database (name is @FullName) andthen creates a table within that database. Is it possible to wrap thesethings into a transaction such that if any one of the following fails, thedatabase "creation" is rolledback. Otherwise, I would try deleting on errordetection, but it could get messy.IF @Error = 0BEGINSET @ExecString = 'CREATE DATABASE ' + @FullNameEXEC sp_executesql @ExecStringSET @Error = @@ErrorENDIF @Error = 0BEGINSET @ExecString = 'CREATE TABLE ' + @FullName + '.[dbo].[Image] ( [ID][int] IDENTITY (1, 1) NOT NULL, [Blob] [image] NULL , [DateAdded] [datetime]NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]'EXEC sp_executesql @ExecStringSET @Error = @@ErrorENDIF @Error = 0BEGINSET @ExecString = 'ALTER TABLE ' + @FullName + '.[dbo].[Image] WITHNOCHECK ADD CONSTRAINT [PK_Image] PRIMARY KEY CLUSTERED ( [ID] ) ON[PRIMARY]'EXEC sp_executesql @ExecStringSET @Error = @@ErrorEND
View 2 Replies
View Related
Mar 26, 2008
I'm new to using SSIS and have been reading and learning slowly how to use it. I'm trying to create an identical copy of our database for reporting. I've used the Import/Export wizard, but have had some issues with foreign keys and with sql_variant columns.
I've tried searching for anything but haven't had any luck as of yet. I guess I don't even know where to start or what to look for.
Any help would be appreciated. Thanks!
View 9 Replies
View Related
Apr 12, 2006
Hi,
I have currently a problem with setting up the permissions for some developers. My configuration looks like this.
DB A is the productive database.
DB B is a kind of "development" database.
Now we have a couple of users call them BOB, DAVID, ...
who are members of the db role db_reader and db_writer for the productive db a but they should be allowed to do nearly everything on db b.
Therefor I added them to the db role db_owner for db b.
For testing purposes I tried to "CREATE" a view TEST as BOB in database B but I received the error message
'Msg 262, Level 14, State 1, Procedure Test, Line 3
CREATE VIEW permission denied in database 'b'.'
I cross checked the permissions on db level and I even granted all available permissions on db level but nevertheless I receive this error message.
What's my mistake?
Of course it worked fine when I give them sysadmin rights but then they have far too much permissions.
Regards,
Stefan
View 8 Replies
View Related
Jan 27, 2006
Hi Minor and inconsequential but sometimes you just gotta know: Is it possible to define a non-primary key index within a Create Table statement? I can create a constraint and a PK. I can create the table and then add the index. I just wondered if you can do it in one statement. e.g. I have: CREATE TABLE MyT (MyT_ID INT Identity(1, 1) CONSTRAINT MyT_PK PRIMARY KEY Clustered, MyT_Desc Char(40) NOT NULL CONSTRAINT MyT_idx1 UNIQUE NONCLUSTERED ON [DEFAULT])which creates a table with a PK and unique constraint. I would like (pseudo SQL):CREATE TABLE MyT (MyT_ID INT Identity(1, 1) CONSTRAINT MyT_PK PRIMARY KEY Clustered, MyT_Desc Char(40) NOT NULL CONSTRAINT MyT_idx1 UNIQUE INDEX NONCLUSTERED ON [DEFAULT]) No big deal - just curious :D Once I know I can stop scouring BOL for clues. Tks in advance
View 2 Replies
View Related
Mar 29, 2008
Hi guys
Just a quick one. I have some create scripts that were created for mysql and i am wanting to convert them to a
SQL Server create script. I am just wondering if anyone knows of any utilities or codeplex projects, etc that can perform the convert process.
The script is fairly basic but it is not fully compatible but i have a lot of them thus why i want to automate the process. The majority of the script is just table create statements like the following:
Code Snippet
-- -----------------------------------------------------
-- Table `dbo`.`Staff`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `dbo`.`Staff` (
`StaffId` INT NOT NULL AUTO_INCREMENT ,
`IndividualId` INT NOT NULL DEFAULT 0 ,
`PositionId` INT NOT NULL DEFAULT 0 ,
`EmploymentStartDate` DATETIME NULL ,
`EmploymentEndDate` DATETIME NULL ,
`SupervisorStaffId` INT NULL ,
`TerminatedEmploymentReasonId` INT NULL ,
`DeletedFl` BIT NOT NULL ,
`CreateDateTime` DATETIME NOT NULL ,
`CreateUserId` INT NOT NULL ,
`ChangeUserId` INT NOT NULL ,
`ChangeDateTime` DATETIME NOT NULL ,
`VersionNum` INT NOT NULL ,
PRIMARY KEY (`StaffId`) ,
INDEX Individual_Staff_IndividualId_Ref (`IndividualId` ASC) ,
INDEX Lookup_Staff_PositionId (`PositionId` ASC) ,
INDEX Staff_Staff_SupervisorStaffId_Ref (`SupervisorStaffId` ASC) ,
INDEX Lookup_Staff_TerminatedEmploymentReasonId (`TerminatedEmploymentReasonId` ASC) ,
CONSTRAINT `Individual_Staff_IndividualId_Ref`
FOREIGN KEY (`IndividualId` )
REFERENCES `dbo`.`Individual` (`IndividualId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Lookup_Staff_PositionId`
FOREIGN KEY (`PositionId` )
REFERENCES `dbo`.`Lookup` (`LookupId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Staff_Staff_SupervisorStaffId_Ref`
FOREIGN KEY (`SupervisorStaffId` )
REFERENCES `dbo`.`Staff` (`StaffId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Lookup_Staff_TerminatedEmploymentReasonId`
FOREIGN KEY (`TerminatedEmploymentReasonId` )
REFERENCES `dbo`.`Lookup` (`LookupId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
Thanks for the help
Anthony
Note: i know if you have a mysql database you can go from one to the other, but i specifically need to take these mysql create scripts and convert them to sql server create scripts and there are a LOT of them i.e. more than 1000 script files that each contains a couple of hundred table create statements.
View 4 Replies
View Related
Aug 17, 2006
Hi,
I've tried those two operations in the Management Studio.
Though we can create a mining structure and mining model in Management Studion,
but we cannot process the analysis-service database.
(1) I create only a mining structure through CREATE MINING STRUCTURE.
No error reported. But if I process the analysis-service database in Management Studio I always get error
'Error : The '<mining_structure__name>' structure does not contain bindings to data
(or contain bindings that are not valid) and cannot be processed.
I then tried to create it by creating and running an XMLA script. It was successful.
However, it's much harder to learn XMLA.
If any of you created an analysis-service database in Mgt Studio, and create a mining
structure in the same place using DMX script, can you process the database?
(2) Is there any use of CREATE MINING STRUCTURE operation without binding
to any table? Examples I saw so far did not show relating it to do. In my experience
processing the analysis-service database with that mining structure is doomed to fail.
(3) Is there any way we can create mining structure through CREATE MINING
STRUCTURE operation in Management Studio and use RELATED TO clause
to bind it to any Relationship to an attribute column (mandatory only if it applies), indicated by
the RELATED TO clause
(4) If this is the fact, is there any use of CREATE MINING STRUCTURE operation?
If we use BI Dev Studio, it's much easier to use the wizard.
(5) I found I cannot create a mining model inside a mining structure through operation
CREATE MINING MODEL. If you call that operation, you end up having a mining
model and a mining structure with the same name. I found that in order to create a
mining model inside a mining structure you have to call operation ALTER MINING
STRUCTURE ADD MINING MODEL. Is it true this is the only way?
Thank you,
Bernaridho
View 3 Replies
View Related
Oct 2, 2007
I am using SQL express and Visual web developer on windows Vista.
When I try to create a new database the following message appears.
CREATE DATABASE permission denied in database master (error 262)
I log on to my computer as an administrator.
Help appreciated
Prontonet
View 4 Replies
View Related
May 3, 2004
Hello all,
Please help....
I have a text file which needs to be created into a table (let's call it DataFile table). For now I'm just doing the manual DTS to import the txt into SQL server to create the table, which works. But here's my problem....
I need to extract data from DataFile table, here's my query:
select * from dbo.DataFile
where DF_SC_Case_Nbr not like '0000%';
Then I need to create a new table for the extracted data, let's call it ExtractedDataFile. But I don't know how to create a new table and insert the data I selected above into the new one.
Also, can the extraction and the creation of new table be done in just one stored procedure? or is there any other way of doing all this (including the importation of the text file)?
Any help would be highly appreciated.
Thanks in advance.
View 3 Replies
View Related
Apr 19, 2002
Hi guys.
I am trying to create a procedure which should drop all existing triggers and can create about 40 differnt triggers in a table.
I cant use "GO" statement in a procedure.
Is there any way to create a procedure like that?
I dont want to run this as a script.
please advice.
--Note: Many triggers use same kind of variable names inside.
-MAK
View 1 Replies
View Related
Apr 24, 2001
i need to create a dbo in new databases that i made. i sent them to another SQL server and they do not have any users and especially do not have a dbo as one of the users. i really would like to have detailed directions on this. i know that i've done it before, but i'm beggining to think that it might have been just by accident. thanks!
View 1 Replies
View Related
Apr 6, 2000
Hello,
I need to create a Job from a VB6 application. How to do it ? Somebody Knows ?
Thank you.
Hugo Venturini Loureiro
View 1 Replies
View Related
Jun 1, 2006
I am used to MySQL, so all this MSSQL is a bit new to me..
so I am writnig a perl script to connect to a database and do some querying.
I have to get a DSN to a specific database on my local machine. How do I do this?
I have created a DSN but it just points, it seems, to the machine and not the database itself....
help?
View 1 Replies
View Related
Aug 17, 2004
Greetings,
Using a server base database called Respond (fe) and Sql server 2000 as a (be), I was trying to create a new db. Instead of designing from scratch, I was thinking to copy an existing Respond db, delete existing data, and modify it to fit my new requirements. I'm new to sql server db and would like to know
1. How to delete data from the table (be).
2. How to perform an automatic backup daily (or may be every other day) and how to check if the backup is doing what it was suppose to do in sql server 2000.
Thank you in advance,
OCM
View 3 Replies
View Related
Oct 4, 2006
Hello, everyone:
Does anyone offer the idea where I should create ERD in SQL Server? And how?
Thanks a lot.
ZYT
View 4 Replies
View Related
Mar 2, 2004
i want to give to my user permission to create job , add step to job etc.
i can't do this when my user do not use sa user but i don't want to give him the sa password so how can i do this
eytanb@mekorot.co.il
View 1 Replies
View Related
May 13, 2008
How to create full_text index table
View 1 Replies
View Related
Sep 5, 2006
create proc usp_CatchAddressException @tableName varchar(500) as
set nocount on
begin
declare @sql varchar(500)
truncate table #tempException
set @sql = 'insert #tempexception (id_town, id_voter, ad_str1, nmb_exception )
select a.id_town, a.id_voter, substring(a.ad_str1, 1, len(a.ad_str1) - charindex(' ', reverse(a.ad_str1))), '20'
from HAVA_DCDE.dbo.' + quoteName(@tableName)+ ' a
where substring(a.ad_str1, 1, len(a.ad_str1) - charindex(' ', reverse(a.ad_str1))+1) not in (select nm_street from state_streets )
and a.id_town = '00519''
print (@sql)
exec(@sql)
end
Server: Msg 170, Level 15, State 1, Procedure usp_CatchAddressException, Line 10
Line 10: Incorrect syntax near ', reverse(a.ad_str1))), '.
i cant find where my mistake is. can someone give some inputs?
View 3 Replies
View Related
Jan 31, 2007
This is a really basic question but how to I create a relationship between two tables using the Microsoft SQL 2005 Management Studio?
I have created the two tables but I can't find where to create the relationship.
Thanks,
Miguel
View 1 Replies
View Related
Nov 28, 2007
Hello!
thanks!
View 5 Replies
View Related
Apr 11, 2007
how to create reports without using business intelligence development studio
plz give me a more explanatory answer as how to start with using reporting wizard or report builder or something
thanks
sally
View 1 Replies
View Related
Jul 31, 2006
Good day All
I'm new to databases with C#
There are lots of good examples that use an already existing SQLev db and vs2005, but I'm trying to use VS2005 standard to create the SQLev DB (table, etc), when I try to add a new item, is see only the .mdf selection. (I don't have Full SQL Server or SQL Express on my machine, if that means anything)
Can you please tell me how or point me to an tutorial
Thanks
Mike Greenway
View 3 Replies
View Related
May 22, 2007
Hi guys.
Here is what I want to do:
1. create a small desktop application
2. when this application starts, it will check if the file "...mydb.mdf" file exists in a specified folder
3. if the file doesn't exist, I want to create the database and connect to it using User Instance
How can I create the database?
I tried to connect to SQLExpress and run a script using SqlCommand. It didn't work.
Is there any other way to do this?
Or what is the correct way to do it?
Thanks.
Mircea
View 2 Replies
View Related
Aug 8, 2006
I have data that looks like the following
ID
=====
123456
234567
345678
456789/567890
654321/765432/876543
In some instances, the older system had to store multiple IDs in one field and used a "/" delimiter. Does anyone have any ideas on how to create new rows on the fly and split the IDs out to the new rows?
Thanks in advance.
View 6 Replies
View Related
May 9, 2008
I am trying to create a VB application that would allow me to store the following in a SQL Server 2005 database table, UserLog.The database has the following columns:
UserName (Nvachar)
Time Logged In (Small Date)
Time Logged Out (Small Date)
LogDuration (Nvachar)
So, when a user logs out, I would like the user login details such as User Name, Date & Time Logged In,
Date & Time Logged Out and Duration to be stored in UserLog database table. Thanks
View 6 Replies
View Related
Feb 19, 2008
Hi
How to create a Job, use of job. and please give me the examples..
View 1 Replies
View Related
Jul 17, 2006
I need to check if an index available on table T1 and field F1. If not, create a non-clustered on F1. How can I do this in a stored procedure?
View 1 Replies
View Related
Apr 27, 2007
I have a one to many relationship between two tables. The master table is keyed using an int ID field set to IsIdentity yes and this is the primary key. The field name is ChurchID. Likewise the detail table has such a field as it's primary key and is named ContactID.
I carry the ChurchID field in the detail table and would like to make it the foreign key. I could not find this explained in the two books I have and the help was anything but that )perhaps it's just me afterall).
Well, any help in this matter would be greatly appreciated as I find myself at a standstill until this can be resolved.
Thanks in advance.
View 2 Replies
View Related