all groups > sql server programming > july 2003
Filter by Day: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
how to insert a new field (not the whole row) in SQL?
Posted by John Davis at 7/31/2003 6:51:39 PM
given 2 tables T1 and T2, what is the SQL statement to add a new field for
each record in T2 when there are common records in both T1 and T2?
For example, T1 is:
ID Name
1001 N1
1002 N2
1003 N3
and T2 is
ID Name
1001 N1
1003 N3
1005 N5
After executing ... more >>
Recalculating values?
Posted by Andrew Ofthesong at 7/31/2003 6:51:33 PM
Hi...
i have:
SELECT
DATEDIFF(yyyy, birthdate, GETDATE()) AS Age,
case
when DATEDIFF(yyyy, birthdate, GETDATE())<=17 then 'Teen'
when DATEDIFF(yyyy, birthdate, GETDATE())>17 and DATEDIFF(yyyy,
birthdate, GETDATE())<=20 then 'Young'
else 'Other'
end as ... more >>
Cheap clustering
Posted by Terence Siganakis at 7/31/2003 6:28:54 PM
Hi, I am currently running a large database (1.6 million inserts a day, a
query on that once a second with heaps of aggregate functions) on a single
relatively powerful server, although it is not powerful enough!
As cost is a very large factor I am thinking about clustering. Clustering
to sa... more >>
Problem ON EACH ROW
Posted by Harry Leboeuf at 7/31/2003 6:09:40 PM
Hello,
We are migration for Oracle to Sql-Server but having some problems with the
triggers. This trigger should fire for each row when a delete happens, as,
from what i've found on the net in SqlServer each trigger is automatically
FOR EACH ROW (Oracle Syntax).
But when i'm doing a 'delete f... more >>
Without Cursors?
Posted by Uddhab R. Pant at 7/31/2003 5:49:03 PM
Hi,
I am working on Stored Procedure in MSSQL Server. How can I navigate
throught a table row by row without using cursor within stored procedure?
Uddhab
... more >>
SQL Statement Paging
Posted by Bernard Goh at 7/31/2003 4:29:46 PM
Hi All,
I came up with the following sql to do the paging....
SELECT TOP 10 * FROM ORDERS WHERE ORDERID NOT IN (SELECT TOP 20, ORDERID
FROM ORDERS)
--|Where 10 is my records size per page.
but soon I realise that it is not the most efficient way of doing it ...
any better ways ?
... more >>
selecting top n records that belong to a category for each category using 1 querry
Posted by Alex Uifalean at 7/31/2003 4:27:17 PM
Hello,
I have this problem: 2 tables
tblProductCategories: CategoryID, CategoryName
tblProducts: ProductID, CategoryID, ProductName, ProductRanking
I want to select using one querry the top 5 products for each category of
products ordered descending after the Ranking field.
How can I do th... more >>
Begin Tran programmatically
Posted by MattC at 7/31/2003 4:23:56 PM
I have used the BEGIN TRAN statement from the Query Analyser many times when
running SQL statements that I would like to roll back if I make a mistake.
Can this be done programmatically, i.e, can I call BEGIN TRAN and then make
many UPDATE calls and then if my program produces an error I can th... more >>
Don't see what you're looking for? Search DevelopmentNow.com.
Sort by a field that has Date + id fields
Posted by Marco Napoli at 7/31/2003 3:50:20 PM
I am using SQL Server 2000
SELECT (RTRIM(contacts.leave_date) + str(contacts.id)) AS DateId
FROM contacts
ORDER BY DateId
When the results come back, its not sorted by date, but it order by
Alphabetically.
Example:
July 7, 2003 120000
July 8, 2003 131000
June 1, 2003 150000
I w... more >>
Stopping errors when casting from varchar to int
Posted by Chris Lacey at 7/31/2003 3:46:02 PM
Hi,
I have a table with a column 'foo' of type varchar containing lots of
values. Most of the values can be cast as int, and I need to get the
maximum, i.e.
SELECT max(cast(foo as int)) ...
However, there are some values of foo which can't be cast as int, and I want
these to be ignored,... more >>
Data from stroed procedure to Cursor
Posted by Xolek at 7/31/2003 3:27:12 PM
Hi,
Please help me if it is possible to put data received from existing stored
procedure into the cursor.
I can not redefine that stored procedure to use cursor output variable.
Thanks in advance,
Aleksander Kaczmarek
... more >>
Begin & End of Week calc ??? Help!!
Posted by chris at 7/31/2003 2:38:33 PM
Given a datetime column in a resultset, how do I calculate
the Beginning of the Week and End of Week dates using a
custom week of Saturday to Friday?
Thanks in advance.
Chris
example:
DateCol1 BeginWeek EndWeek
-------- --------- -------
7/1/03 6/28/03 7/4/03
7/8/0... more >>
BCP and Excel
Posted by Tommy at 7/31/2003 2:37:26 PM
I am not sure if this is the right forum for this question but hopefully
someone can help me.
I need to BCP a large amount of data into sql server. I have txt files
working ok. I need to know if I can BCP excel files. I don't find any
mention of that in the BOL.
Thanks for any tips.
Tomm... more >>
AutoNumber in SQL Server
Posted by S R at 7/31/2003 2:15:01 PM
Hi,
I need to import a few tables in SQL server database
(7.0) , from another SQL server databse (2000). The
original table has autonumber as the primary key and
another table has a foreign key relationship to this table
on the autonumber key. Now, when i import the data to the
sql ser... more >>
VERY SIMPLE QUESTION ABOUT A VIEW
Posted by JESS at 7/31/2003 2:14:10 PM
In the following query, (Value1 - 5) as Value2 is not
admissible. SQL does not acknowledge Value1 as a column
(it displays that error).
The SELECT statement corresponding to Value1 is a very
complicated one and I do not want SQL to calculate Value2
as (SELECT COUNT(...) FROM Table2...) -... more >>
rowid , decode
Posted by afshin at 7/31/2003 2:13:28 PM
Is there any equivalence to ROWID feature that is in ORACLe
in SQLSERVER.
Also any equivalence to DECODE statement.
Thanks... more >>
only getting first 256 chars of text field
Posted by gregg durishan at 7/31/2003 1:56:10 PM
I have a simple query to pull a large comments field. the
query succeeds in drawing in all the data when the query
is bound to a form or report, but when I run it in query
analyzer or try to output the query to excel, i only get
the first 256 chars of the field.
what shall i do?
... more >>
More of the same...(sorry about the cross-post)
Posted by David Sanders at 7/31/2003 1:29:27 PM
Is there any way, shape or form that the following stored procdure can be
called successfully? Basically I am trying to passing in a WHERE clause
that contains some full-text predicates (CONTAINS, etc...). This WHERE
clause has to be a variable passed in. The 'public' role has NO rights to
th... more >>
converting a to_date format from orcl to sql server
Posted by Alex Ivascu at 7/31/2003 1:20:40 PM
I have a to_date function, which formats the date to this: 'MM/DD/YYYY
HH24:MI:SS'
In sql server, is there another way of accomplishing the same thing -
besides this? select convert(char(11), getdate(), 101)+ convert(char(8),
getdate(), 108)
Thank you.
Alex Ivascu
... more >>
Equivalent to Oracle's START AT .... CONNECT TO for tree ordering
Posted by Vidar Ligard at 7/31/2003 1:12:30 PM
Folks,
Here is a classic:
I have a table with a hierarchical listing (be it
directory tree, process tree, whatever) with an ID and a
PID field, like so:
ID PID Name
1 <null> WinNt
2 <null> Programs
3 1 System32
4 2 MSOffice
5 3 Drivers
Of course, I want the data to... more >>
timestamp data type
Posted by Simon at 7/31/2003 1:09:25 PM
If I have a timestamp column in my product table, how can I select only
updated products from the last time?
Should I campare:
SELECT * FROM products WHERE Timestamp>oldTimeStamp
oldTimestamp I remember from the last SELECT from the last week for example.
Why use timestamp instead of da... more >>
TSQL Debugger datetime parameters will not accept seconds
Posted by Ray Pollard at 7/31/2003 12:40:11 PM
In using the TSQL Debugger to debug a stored procedure, I
am running into a problem specifying a value for a
datetime parameter when the datetime value has any nonzero
seconds. The debugger accepts 2003-07-29 11:33:00 but
will not accept 2003-07-29 11:33:01. When placing the
latter value... more >>
will newid() ever return a character?
Posted by Alex Ivascu at 7/31/2003 12:14:08 PM
if used like this: select convert(bigint, convert(varbinary, newid()))
Thanks in advance.
Alex Ivascu
... more >>
TSQL Question
Posted by JLS at 7/31/2003 12:13:24 PM
I am drawing a complete blank, please help the weak of mind....
I want to write one select statement. I want to select the bill to key =
column if it is not null, OR the customer key column if it is not null =
for a record where the account number is X and the routing number is Y.
Record wo... more >>
Optimizing SQL Select
Posted by Saga at 7/31/2003 12:05:32 PM
Hi all,
I have this SQL statement:
select count(*) from tblOrders where
id='xyz' and orderDate='some date'
tblOrders has about a million records and an index on id and orderDate
When I execute this it is FAST, no probem there, but now I need a
specific column, so count(*) won't cut it, s... more >>
calling procedure within function
Posted by Alex Ivascu at 7/31/2003 11:40:31 AM
Hi again. I'm trying to use a function to return the value that the
procedure within the function will give back.
Here's the code for the procedure (all it does it increments the value in
the dual table by one, and returns the new value):
create procedure sched_seq_get (@vi_seq_name nvarchar... more >>
Tough SQL!
Posted by Yaheya Quazi at 7/31/2003 11:39:06 AM
Hi here is some sample data
order_number Line Number Price
8908ABB23200 1 4
8908ABB23201 1 5
8908ABB23201 2 6
8908ABB23202 1 7
8908ABB23202 1 8
8908ABB23202 2 9
order_number Line Number Price
8908ABB23200 1 5
8908ABB23201 2 6
8908ABB23202 1 8
8908ABB23202 2 9
I want to create a ... more >>
Passing a variable via NET SEND
Posted by Fred at 7/31/2003 11:22:10 AM
I have a SP's that monitors growth and I want it to send
me a "net send" when a certain criteria is met.
I have no problem sending a regular net send, but need to
pass the dbname as a variable. Here's what I have so far..
if @maxsize < (@size + @growth)
begin
EXEC master..xp_cmdshell 'net... more >>
why view runs slow?
Posted by F HS at 7/31/2003 11:14:12 AM
Hi!
I have a SQL code that takes 5-6 minutes to run in QA but when I create
a view using the same code and try to run this view i.e. select * from
myview, its takes forever??? please help!!!
i am using sql server 7.0
*** Sent via Developersdex http://www.developersdex.com ***
Do... more >>
Stored Proc with dynamic datename property
Posted by Russell NO[at]SPAM highfell.ca at 7/31/2003 11:11:28 AM
I am trying to write a stored proc that uses a dynamic value to set
the <datepart> parameter of the datename function
datename(<datepart>,<date>)
here is the test query I am using against northwind:
select Shipcountry, datename(weekday,orderdate) as omonth,
sum(extendedprice) totalEP from ... more >>
Cursor
Posted by Yaheya Quazi at 7/31/2003 10:59:24 AM
Hi this maybe very elementary for some people. But I have
this sql
set nocount on
declare @order_items int
declare @counter int
declare @order_num char(10)
Select @order_items = 0
Select @counter = 0
select @order_items = Count(*) from order_detail_org
While @counter < @order_ite... more >>
Problem with Locking in MS-SQL 2000
Posted by ppdewan NO[at]SPAM yahoo.com at 7/31/2003 10:52:30 AM
There is a starange problem happening in our Application. We have big
Transaction and as a part of that transaction we are inserting
multiple rows in the same table. When we run the first instance of
this transaction it runs fine. Then we start the second instant of the
same transaction and the ... more >>
rename all Primary Keys in db
Posted by Philip at 7/31/2003 10:48:41 AM
Hi all,
I want to be able to retrieve and rename all the primary
keys in a db for all tables that start with ad_ or wk_
I know that when you add a constraint that is a foreign
key you can set the name. Trouble is, when you add a
foriegn key constraint it's not possible to add a name.
... more >>
How do you store an office document in SQL
Posted by John Beavers at 7/31/2003 10:46:28 AM
I am desinging a table that will contain information on
employees. One of the things I would like to store are
word documents or excel documents. How do I store the
documents in the database?
... more >>
catching error messages in stored procs
Posted by Nathanael LHeureux at 7/31/2003 10:28:46 AM
I want to get the error text from an insert query that is
run within a stored procedure to save in an insert reject
table for later analysis.
I know how to check @@error and get the error number and
even look up the generic text in sysmessages, but I don't
know how to get the full message... more >>
How to have Sql2000 generate a CrossTab type recordset
Posted by Ron Weiner at 7/31/2003 10:04:33 AM
I am new to this Group, and have little Sql experience. As an Access guy I
have long used Access Crosstab queries to wow and amaze customers. As you
all know (as I have just discovered) Sql 2000 doesn't know anything about
Transform and Pivot.
Soo... How can I create the equivalent of an Acc... more >>
GUID
Posted by Balaji at 7/31/2003 10:01:45 AM
Hi
I want to know how GUID is globally unique identifier?
How can no other computer in the world will generate a duplicate of that
GUID value?
Can any one explain to me about this.
Regards
Balaji
... more >>
How can I combine two records in one record in a SP?
Posted by Sam at 7/31/2003 9:30:04 AM
Hi,
I want to combine two records into one. Let's say I have 3 fields in the
record -- ID, Name, Description. My current SP returns two records with
these 3 fields. What I'd like to get is ID1, Name1, Description1, ID2,
Name2, Description2 in one record.
Thanks
Sam
... more >>
Random query
Posted by Brian Martin at 7/31/2003 9:05:35 AM
Is it possible to return data in a random order from a
query each time the query is run.
If so, how is this done?
Many thanks,
Brian Martin... more >>
Selecting and Appending
Posted by Jake at 7/31/2003 8:57:22 AM
With the following query:
create table #t
(
customerid varchar(50),
calltime datetime
)
insert into #t (customerid,calltime) values ('123', '12:01
PM')
insert into #t (customerid,calltime) values ('123', '9:30
PM')
insert into #t (customerid,calltime) values ('123', '8:57
PM')
ins... more >>
Running DDL Scripts - Newbie Question
Posted by Leonard at 7/31/2003 8:51:32 AM
I use the Database solution in Visio to design databases.
It can generate DDL scripts for creating databases. How
can I use those scripts to generate the database in SQL
Server 2000?
Thanks.... more >>
Max question
Posted by Craig at 7/31/2003 8:48:25 AM
TheTable =
TheDate datetime
TheHour int
TheTemp int
This tracks the hourly tempature
I want to find the Max temp and what day it occured on for each year and
month
Select
year(TheDate)AS [TheYear],
Month(TheDate)AS [TheMonth],
Max(TheTemp)
from TheTable
Group by year(TheDat... more >>
Subquery message
Posted by sgpgpjr NO[at]SPAM yahoo.ie at 7/31/2003 8:45:06 AM
Hi all,
I have a query as follows:
update stage.FinanceVehicleSummary
set vin = (select VIN from stage.ChasisLookup where
stage.chasislookup.chasis = stage.FinanceVehicleSummary.ChasisNo
and stage.chasislookup.sr_registration_number =
stage.FinanceVehicleSummary.srregno)
and i ... more >>
Cdonts: Why doesn't this work, it did before...
Posted by JDP NO[at]SPAM Work at 7/31/2003 7:55:51 AM
declare @obj int ,@err int ,@body varchar(100)
set @body = 'Testing....TSQL and Cdonts...'
declare @obj int ,@err int
exec sp_oacreate 'cdonts.newmail' ,@obj output
print @obj
exec @err = sp_oasetproperty @obj ,'from' ,'jpmgt@NoSpamsbcglobal.net'
exec @err = sp_oasetproperty @obj... more >>
sp3
Posted by wangc NO[at]SPAM alexian.net at 7/31/2003 7:53:54 AM
Most of the installations of sp3 are smooth, but I got error messages
couple times like this: "Error runing script: sp1_uni_sql(1)" Can
someone help to solve this problem?
--Saiyou... more >>
Trying to execute "USE"
Posted by bueno501 at 7/31/2003 7:51:42 AM
Hello All,
If you can shed some light on this, so any help is appreciated. I am trying
to execute the "USE" @databasename within a stored procedure. But when I
run the SP, it doesn't change database to the specified database. Am I
doing something wrong? Is this possible? If not, is there ... more >>
HEXIDECIMAL CONFUSION
Posted by BARBARA FLOYD at 7/31/2003 7:34:31 AM
Hiya,
this may be simple if you know hex calculations but its
got me very confused!!
In my table I have a field called unitNumber. I want to
return the rows where this field has a 6 in the 5th
position (e.g. 60001, 60586, 62323 etc)
I have tried
select * from table
where (unitNum... more >>
can I import an excel pivot table to sql table?
Posted by ALF at 7/31/2003 7:04:58 AM
or better still, can I query the excel pivot table from
sql ?
ALF... more >>
GetDate()
Posted by Greg at 7/31/2003 6:56:29 AM
When I employ the GetDate function, in inserts the date
with a timestamp. Is there any way to have it simply
input only the date? TIA... more >>
When was a stored procedure modified?
Posted by Joe Erpenbeck at 7/31/2003 5:57:39 AM
Does anybody know how to determine when a stored
procedure was last modified? The crdate or refdate in
the system table sysobjects only shows when the stored
procedure was created.
... more >>
|