SELECT Name, TagID,
(SELECT COUNT(TagID) AS Expr1
FROM dbo.mw_PagesTagMap
WHERE (TagID = tag.TagID)) AS TagWeight
FROM dbo.mw_Tags AS tag
This query works exactly how I want it to.
I would like to modify this to NOT return any column that has a TagWeight of 0
SELECT Name, TagID,
(SELECT COUNT(TagID) AS Expr1
FROM dbo.mw_PagesTagMap
WHERE (TagID = tag.TagID)) AS TagWeight
FROM dbo.mw_Tags AS tag
WHERE (TagWeight <> 0)
I thought this would do it but I'm getting an error "invalied column TagWeight".
How would I get this to work?
Hi, i have been able to create a query in asp.net in the sever explorer. I want to create an statement as a new column. In Access i would do it like this (Agg: [Scored]-[Against]) But how do i call a new column Agg in SQL and then tell it to take Against away from Scored?
I am working with employee schedules. Each schedule is comprised ofsegments (shift, lunch, break, training, etc.) that have rankings.Each record has the employee id, the date the shift starts, the startand end time of each segment, the duration,the segment type and itsrank. The start and end times of the schedules can overlap, but thesegment that has the higher rank takes precedence.As a simple example, an employee working 8a-5p will have two records.The shift segment from 8a-5p and a lunch segment from 12p-1p. Thelunch ranks higher so, even though the shift goes from 8a-5p, from12p-1p, the lunch takes precedence.What I'm trying to do is build a query that will collapse the segments.So given the example above, I will now have three records: shift8a-12p, lunch 12p-1p, shift 1p-5p.I have been racking my brain but I just can't figure it out.Ultimately, a programmer in my office will display this in a bar chartformat with each segment type having its own color. I'm trying to do asmuch of the work in SQL so he doesn't have to calculate this stuff inthe code.Any help would be appreciated.Thanks.Angela
Hey all, am a bit new to SQL so excuse my ignorance I am wanting to create a query that uses 2 parameters and returns 20 random records that meet the criteria. One of the parameters is stored in a different table to the one im querying, and the other is a selection made by the user on a VB form.. If its any help, my table schema is:
I don't see what's wrong with this command. >> Create View BCPOutBatchWeightTaiwan AS Select * from batchWeight a JOIN Geography b ON a.GeographyPtr = b.GeographyPtr where b.countrycode = 'tw' << I get the following error if I try to create it. >> Server: Msg 4506, Level 16, State 1, Procedure BCPOutBatchWeightTaiwan, Line 2 Column names in each view must be unique. Column name 'GeographyPTR' in view 'BCPOutBatchWeightTaiwan' is specified more than once. <<
But it runs fine if I run only th 'Select' part of the command without 'CREATE' line.
I have a table with the following columns: Rtype, Amount, Refnumber, Color: Here is what the table looks like:
RD 25 1 blue AB 45 2 green AC 25 3 purple AD 34 4 blue AE 25 5 pink
Now lets say I would like to create new transactions for all 'RD' Rtypes, but I would like to change the Amount to lets say, 99 for all of 'RD' types, but keep the same refNumber. For example, I want to create and insert a new transaction for RD, but with the amount 99, so that the row looks like this:
RD 99 1 blue
Where do I put in the query to change the Amount value? I do not wish to use the update function, because I actually want to create a new row. The query I am using, but not working is:
INSERT INTO EMPLOYEES(Rtype, Amount, Refnumber, Color) SELECT Rtype, Amount, Refnumber, Color FROM Employees WHERE Rtype = 'RD'; Reply With Quote
I need to create a "simple" sql query but have it formatted and then emailed to individuals. I am trying to convert over from Oracle but I am having a hard time getting the query to be formatted the way I want. Here is the select statement I tried to use with no luck with xp_sendmail:
SELECT ALARM ID, TIMESTAMP as TIME, CLASS, RESOURCE, P, L, F, ALARM_MESSAGE FROM ALARM_LOG WHERE ([TIMESTAMP] < GETDATE() - 1) ORDER BY [TIMESTAMP];
Here what the output should look like with the column headers underlined and then the column data (notice the column heading ALARM MESSAGE is on the next line before any data):
ALARM ID TIME CLASS RESOURCE P L F -------------------- ----------- ----- ---------------- - - - ALARM_MESSAGE ------------------------------------------------------------- B3_TEMP_ALM 02-02@11:21 ALARM BUILDING3_TEMP N G G BUILDING 3 TEMPERATURE ALARM, CALL SECURITY.
B5_TEMP_ALM 02-02@11:22 ALARM BUILDING5_TEMP N G G BUILDING 5 TEMPERATURE ALARM, CALL SECURITY.
How can I run the query and have it formatted and emailed out? What is the best way to accomplish this?
select c.name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID where t.name= 'Hosea_tblDATA_NOTES'and c.is_identity = 0 order by column_id
I was thinking if it is possible to create a table from the results of this query, my table name(in this case 'Hosea_tblDATA_NOTES') will be a parameter, that whatever table name I pass, with the results I get I will be able to create another table, assuming all data types are varchars, but it should be generic.
I want to create a new table with the about of that query, that output has to be my columns.
Im just wondering if it is possible to use a SQL DB to query game servers, Im very new to SQL, an if it is possible please lead me in the right direction on start this.
I have a question about using the query builder, or just straight sql, to create expressions. My first example caused the query builder to generate a query configuration error:
Expression: EIM_REQUISITION_DETAILS.EST_UNIT_COST * EIM_REQUISITION_DETAILS.REQRD_QTY AS COST
Syntax error: Expecting "," or "FROM" after column alias or "*"
Initially I thought I was dead in the water but then I decided to just run it anyway and it worked! I got my cost. OK so fine the query tool doesn't recognize some sql expressions. Because I am trying to make a large flat file I thought I'd concatenate 2 fields to generate a recognizable requisition, which everyone knows is the year followed by a hyphen then the req number:
My old Access query had this: Req: Right([REQ_YR],2) & "-" & [REQ_NO]
and I tried to change it to this: substring (EIM_REQUISITIONS.REQ_YR from 2 for 2) || '-' || EIM_REQUISITIONS.REQ_NO AS REQ
So apparently my older sql book doesn't have the syntax right. Since I plan to do more of this could someone point me to a reliable book or site that could help me with sql syntax?
I have a stored procedure that supplies rows for a front-end DataGrid that allows custom paging. The stored procedure must return the requested "page" of rows as identified by a sproc argument. Currently, I'm loading the the query's result set into a temporary table that has an identity column as primary key. I then run a second query against the temp table that uses the identity column value to strip out the requested "page" of rows and return them to the front-end DataGrid.
I'd like to eliminate the temporary table. To do so I would need to create the equivalent of an identity column in the query's sorted results and reference this value in the WHERE clause in order to return only the requested rows.
Does anyone know of a way to generate a sequential number (starting at 1) within a query (and after the rows have been sorted by the ORDER BY)? I don't think this can be done but I put it out for those who may know better.
Thanks for your help. If you know this is impossible, that would be helpful feedback as well.
I am trying to write a SQL query looking for a specific file in a specific directory. If the File does not exist, then I want it to display.
here is the Code that I have for it that shows that the file exists... how do I make it show that the file doesn't exist?... what am I doing wrong?
Thanks for all your help in advance!
**********************************
SELECT TOP 100 PERCENT SYS.Netbios_Name0, SYS.User_Name0, SF.FileName, SF.FileVersion, SF.FileSize, SF.FileModifiedDate, SF.FilePath, SYS.Operating_System_Name_and0 FROM dbo.v_GS_SoftwareFile SF INNER JOIN dbo.v_R_System SYS ON SYS.ResourceID = SF.ResourceID WHERE (SF.FileName = 'UdaterUI.exe') AND (SF.FilePath = 'C:Program FilesMcAfeeCommon Framework') OR (SF.FileName = 'UdaterUI.exe') AND (SF.FilePath = 'c:Program FilesNetwork AssociatesCommon Framework') ORDER BY SF.FileVersion, SYS.Netbios_Name0
On a new project i need to create possible ranges between a specific interval.
suppose i have this main product:
main product : LY E67F
Also, in first level i have a table classify by Group depending on Intensity.
table group Group intensity AA 1120 AB 1400 BA 1800 BB 2240 CA 2800
I need to create these diferent options:
1 option : AAAB or AABA or AABB or AACA 2 option : ABBA or ABBB or ABCA 3 option : BABB or BACA or BBCA or beginning from the end 1.option CABB or CABA... or beginning from the middle 1.option BBBA or BBAB and so on.
I fact, i need to find all available options possibles to build article code, like a matrix.
I have a problem creating a SELECT query which involves getting the FIRST occurrence, the SUMS and the LAST occurrence of a selected row. I have two tables A and B which has the following data:
Table A
---------------------------------------------------------------- |Item ID | Item Name | Item Description | Current Quantity | ---------------------------------------------------------------- ----1------------Bolts-------------35"----------------20 ----2-----------Paint----------GOLD Paint------------30 ----3-----------Screws------------30"----------------40 ----------------------------------------------------------------
and Table B
-------------------------------------------------------------- |Log ID | Item ID | Beginning | Add | Less | Ending | Date | -------------------------------------------------------------- ---1---------1----------30-------0-----10------20------04-04 ---2---------2----------40-------10----10------40------04-04 ---3---------3----------50-------5-----10------45------04-04 ---4---------1----------20-------0-----0-------20------04-05 ---5---------2----------40-------0-----10------30------04-04 ---6---------3----------45-------0-----5-------40------04-04 -------------------------------------------------------------
and I have two datetime pickers, one FROM date picker and a TO date picker If a user selects FROM 04-04 TO 04-05...I want a select statement which will select the Item Name and Desc, the BEGINNING QUANTITY (in reference to the FROM DATE), the SUM of Adds and Less and the ENDING QUANTITY (in reference to the To Date) and then group by their Item ID
In this case, it will generate a table like this
---------------------------------------------------------- Item Name | Item Desc | Beginning | Add | Less | Ending | ----------------------------------------------------------- --Bolts---------35"---------30---------0-----10-----20 --Paint-----Gold Paint------40---------10----20-----30 --Screws-------30"---------50---------5-----15-----40
"SELECT A.Item Name, A,Item Desc, B.Beginning=(select B.Beginning from Table B where A.Item ID = B.Item ID AND Date = From Date), SUM(B.ADD), SUM(B.LESS), B.Ending=(select B.Ending from Table B where A.Item ID = B.Item ID and Date = To Date) WHERE A.Item ID = B.Item ID and Date(B.Date)>From Date AND Date(B.Date)< To Date group by B.Item ID order by A.Item Name, Item Desc"
My query returns the right Item Name, Desc, the Sum of Add and Less.My problem is that I can't get the value of my beginning and ending.I think I have a problem in A.Item ID = B.Item ID. As I tried a fixed value condition, (B.Item ID = 2), it will get the right result), I'm guessing the program is not getting A.Item ID.
I have the TAMCreate.sql file which contains the script to create all tables in the Database TAMaintenance. Its created and used in the SqlServer 2000. But i have only SqlServer 7. From the script i copy and paste each table and created upto 7 tables without any problem, when i create the 8th table i get the following error the code for the table
CREATE TABLE AA_Branch_Master( Branch_Code varchar(15) CONSTRAINT PK_AA_Branch_Master1 PRIMARY KEY, Branch_Name varchar(50) NOT NULL, Branch_Opened datetime NOT NULL, Branch_Location varchar(50) NOT NULL, Branch_Province varchar(25) NOT NULL, Branch_Incharge varchar(50) NOT NULL, Branch_Remark varchar(150), Branch_Status BIT(1)) go
Error: Server: Msg 2716, Level 16, State 1, Line 1 Column or parameter #8: Cannot specify a column width on data type bit.
In the same way i have get the error or another table, rest of the tables are created successfully.
the code for the table
CREATE TABLE AA_Supplier_Master( Supp_Code varchar(15) CONSTRAINT PK_AA_Supplier_Master1 PRIMARY KEY, Supp_Name varchar(100) NOT NULL, Supp_Address varchar(150) NOT NULL, Supp_Contact_Person varchar(50) NOT NULL, Supp_Paymode varchar(25) NOT NULL, Supp_Tel1 varchar(25), Supp_Tel2 varchar(25), Supp_Fax varchar(25), Supp_Postbox varchar(15), Supp_Postal_Code varchar(15), Supp_City varchar(50) NOT NULL, Supp_Country varchar(50) NOT NULL, Supp_Status BIT(1)) go
Error: Server: Msg 2716, Level 16, State 1, Line 1 Column or parameter #13: Cannot specify a column width on data type bit.
Dear Readers, Is it possible to create a query that access multiple sql express databases? Or is it possible to link a table in one database from another?
I've written a Union query that joins 16 different tables. I need to somehow make this into a permanent view so that i can query directly from excel to extract specific data - i guess i can set up excel to pull straight from this view then ?
I'm used to running excel VB code to SQL via Access (linking access up) but want to cut out the middleman now.
Any ideas ?
An example of the Union Query i have built is below :
I've been searching around for some info on how to set this up, but with no luck.I need to have a .sql file that will set up a few tables and these tables will have relationships and contraints.I can do this by hand in enterprise manager, but need to set up some procedures that will do the same thing.For instance, I can create the tables just fine.....CREATE TABLE students ( sId int NOT NULL PRIMARY KEY, studentId varchar(50) NOT NULL, course varchar(50) ) CREATE TABLE courses ( cId int NOT NULL PRIMARY KEY, course varchar(50) NOT NULL, sco varchar(50) )But, I need to set up relationships in there somehow.Once student may have many courses (one to many) and one course may have many sco's (one to many) SCO would be another table.Can someone point me to a good link that would show how to complete these procedures?Thanks all,Zath
I have to write a couple scripts that will update a couple columns in two separate tables and also insert a new row with the same data except for a few calculated or provided values ...... see specs below ...
1. tGradeHist Table Script One (Needs to be run first)
a. Read tGradeHist Table and Select rows with GradeEndDate = NULL and GradeStartDate = '1/1/2007 12:00:00 A.M.'
b. Calculate New Step Amount = StepAmount * Incr% (Round To Nearest Whole Dollar)
c. Create New Row for this table using information from row read above and insert new information where indicated :
GradeCode - Same
GradeLocationCode - Same
Step - Same
GradeStartDate - '7/1/2007 12:00:00 A.M.'
GradeEndDate - NULL
GradeCurrencyCode - Same
StepAmount - Result of b (above)
GradeFrequencyCode - Same
RangeMaximumAmount - Same
RangeMidAmount - Same
RangeMinimumAmount - Same
GradeCurrentFlag - 'True'
MarketMaximumAmount - Same
MarketMidAmount - Same
MarketMinimumAmount - Same
GradeGUID - Same
TSCOL - Same
d. Update Row read in a (above) with GradeEndDate = '6/30/2007 12:00:00 A.M.' and GradeCurrentFlag = 'False'
2. tPersonBasePayHist Table Script Two (Needs to be run second)
a. Read tPersonBasePayHist Table and Select rows with PersonBasePayEndDate = NULL
b. Calculate New PersonBasePayAmount = PersonBasePayAmount * Incr% (Round To Nearest Whole Dollar)
c. Create New Row for this table using information from row read above and insert new information where indicated :
PersonGUID - Same
PersonBasePayStartDate - '7/1/2007 12:00:00 A.M.'
PersonBasePayEndDate - NULL
PersonBasePayCurrencyCode - Same
PersonBasePayAmount - Result of b (above)
PersonBasePayFrequency - Same
PersonBasePayPayrollFrequencyCode - Same
BasePayReasonCode - 'SA'
ConductedBasePayReviewDate - Same
ScheduledBasePayReviewDate - Same
PayrollCode - Same
PersonBasePayCurrentFlag - 'True'
ApprovedByPersonGUID - Same
PersonBasePayGUID - Same
TSCol - Same
d. Update Row read in a (above) with PersonBasePayEndDate = '6/30/2007 12:00:00 A.M.' and PersonBasePayCurrentFlag = 'False'
I'm wondering if there is some sql I can run to check properties on a table. This would be used to verify things like data types, allow nulls and default values have been set to avoid mistakes. This could be done manually one table and one column at a time, but it would be a lot easier to look at it in the results window.
I have the following report I need to create with 2 parameters. An equal OR not equal. I need the report to have a drop down that has equal to '1024' or a drop down option that IS NOT equal to '1024'. I also need the WHERE clause to return the equal or not equal based on the user selection inside of SSRS.
SELECT user1 AS [Company], reference AS [PAI_REF], statenumber, LEFT(user4, 7) AS [Supplier Code], user4 AS [Company Information], user8 AS [Transaction Type], user2 AS[Invoice Number], --CONVERT(VARCHAR,CONVERT(Date, user3, 103),101) AS [Invoice Date], [routeName] AS [Route], username AS [User Name]
I am working to create a phone list that will contain Last Name, First Name, and Phone Number sorted by last name. For printing purposes I would like to have three columns of data instead of the standard of one column.
Is it possible to create a query to present data in three columns showing the data side by side?
-- Get the new Customer Identifier, return as OUTPUT param SELECT @NoteID = @@IDENTITY
-- Insert new notes for all the users that the note pertains to, in this case this will be by the assigned -- users. IF @FK_UserIDList IS NOT NULL EXECUTE spInsertNotesByAssignedUsers @NoteID, @FK_UserIDList
-- Insert New Address record -- Retrieve Address reference into @AddressId -- EXEC spInsertForUserNote -- @FK_UserID, --@NoteID, -- @BeenRead -- @Fax, -- @PKId, -- @AddressId OUTPUT
COMMIT TRANSACTION
-------------------------------------------------- GO
ok can someone tell me why i get two different answers for the same query. (looking for last day of month for a given date)
SELECT DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, CAST('12/20/2006' AS datetime)) + 1, 0)) AS Expr1 FROM testsupplierSCNCR I am getting the result of 01/01/2007
Hi,I have a User Defined Datatype, which I want to use to define anotherdata-type. I tried the obvious:EXEC sp_addtype@typename = UDT_OBJECT_ID,@phystype = 'NUMERIC (5)',@nulltype = 'NULL'GOEXEC sp_addtype@typename = UDT_TRACKING_NUM,@phystype = UDT_OBJECT_ID,@nulltype = 'NOT NULL'GObut that didn't work :Msg 15036, Level 16, State 1, Server SKINNER, Procedure sp_addtype, Line 186The data type UDT_OBJECT_ID does not exist.Has anyone done this before,Thanks,Rowland.