all groups > sql server programming > july 2004 > threads for tuesday july 20
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
'select case' in stored procedure ?
Posted by Agnes at 7/20/2004 11:20:07 PM
Can I use select case in "stored procedure ???
If yes, can someone be kind to give me a sample ??
Thanks
From SQL-newbie
... more >>
Concatenating
Posted by Khurram Chaudhary at 7/20/2004 11:11:23 PM
Hi,
I have an SP that returns results as follows:
UserName AccessAllowed
Khurram Read
Khurram Write
Tim Write
James Write
Tim Delete
How can I get the resul... more >>
Re: Need help with a simple view problem
Posted by Lisa Pearlson at 7/20/2004 10:58:32 PM
Thanks Jacco. Your code makes more sense to me than the one by John Gilson.
In some_table, there is actually 1 more column, "year".
if select the year into the rest like this:
SELECT t.[year], m.[Month], .....
the result shows only the year for the records that exist in some_table
(obviou... more >>
exhibit in a column in view, number formatted
Posted by Frank Dulk at 7/20/2004 9:38:59 PM
to exhibit in a column in view, number formatted with two houses decimals
and point of thousand separate, I ask for the kindness of posting here.
... more >>
Combine 2 queries into 1 query
Posted by Jon Glazer at 7/20/2004 8:32:48 PM
Say I have two queries
q1=select id, blah blah from mytable
and
q2=select id, blah2 blah2 blah from mytable
These queries do fundimentally different things, one being an agragate query
to sum up some stuff, the other is a query to obtain the max value of a
field.
Now I want to com... more >>
Timed query
Posted by Jon Glazer at 7/20/2004 8:03:41 PM
How can I write a query that adds records once a month? The query needs to
add an amount to a register (for a service) based on a customer's current
rate. So say, customer 1 has a rate of $80 and customer 2 has a rate of
$85, at the end of the month I want it to automatically add records to the... more >>
Complicated query
Posted by Just D at 7/20/2004 7:52:56 PM
Hi,
The task is so hard that I even don't know how to start explaining it...(
Let try to write a schema step by step.
We have two basic tables (and a few related subtables) - with questions and
answers. The tblQuestions database table is having the following fields
(simplified):
QID [... more >>
varchar(50) field - how to prevent numbers being entered?
Posted by Ross at 7/20/2004 7:46:01 PM
I have a varchar(50) field. Entries should be only letters or spaces etc but not numbers - is there a CHECK CONSTRAINT expression or a TRIGGER expression that can be written?
Hope somebody can help
Kind regards
Ross... more >>
Don't see what you're looking for? Search DevelopmentNow.com.
Help with SQL Query
Posted by George Durzi at 7/20/2004 7:01:30 PM
have a table called AppUser as defined below
CREATE TABLE [AppUser] (
[Id] [int] IDENTITY (1, 1) NOT NULL ,
[ParentId] [int] NULL ,
CONSTRAINT [PK_AppUser] PRIMARY KEY CLUSTERED
(
[Id]
) ON [PRIMARY] ,
CONSTRAINT [FK_AppUser_AppUser] FOREIGN KEY
(
[ParentId]
) REFERENCES ... more >>
Connecting to SQL Server 2005 Express
Posted by Chris at 7/20/2004 6:57:05 PM
I've just download SQL Server 2005 Express and I am trying to get our
application to work with it. I've attached the database and can
successfully query the database using OSQL. But I can't get our application
to connect. Are connection strings different for SQL Server 2005? Or is
there some... more >>
Need help with a simple view problem
Posted by Lisa Pearlson at 7/20/2004 6:27:45 PM
Hi,
Imagine I have a table with 3 records:
Month, Value
1, 5
2, 8
6, 3
I wish to create a view that always shows months 1-12, with a sum
(cumulative) of the value:
Month, Value, Total
1, 5, 5
2, 8, 13
3, 0, 13
4, 0, 13
5, 0, 13
6, 3, 16
7, 0, 16
8, 0, 16
9, 0, 16
10, 0, 16
11,... more >>
Advanced SQl Programming links
Posted by Panks at 7/20/2004 6:13:52 PM
Can anyone provide me links Advance SQL pragramming tutorials / pdf files
panks
... more >>
Concatinating joins into single field
Posted by Rob Nicholson at 7/20/2004 6:04:05 PM
Consider a SELECT like this:
Select
Category.Name As Category,
SubCategory.Name As SubCategory
From Categories
Inner Join SubCategories
On Categories.CategoryID=SubCategory.CategoryID
A traditional kind of join between parent and child table that generates
output like this:
Co... more >>
SP returned value
Posted by Viktor Popov at 7/20/2004 5:58:14 PM
Hi,
I have this SP:
CREATE PROCEDURE prSVUSERINFO
@USRNAM VARCHAR(20),
@USRPSW VARCHAR(20),
@NAME VARCHAR(64),
@ADDR VARCHAR(74),
@EML VARCHAR(64),
@ROLE VARCHAR(6),
@RCOUNT INT OUTPUT
AS
IF NOT EXISTS( SELECT * FROM BLEK.USERS A WHERE A.USERNAME=@USRNAM OR
A.USEREMAIL=@EML)
BEGIN
IN... more >>
Creating a procedure if it does not already exist
Posted by Jim Coyne at 7/20/2004 5:48:08 PM
I'm modifying some stored procedure scripts to alter the proc instead of
dropping/creating it so that permissions are not lost. In doing so, I'm
trying to use:
if not exists (select * from dbo.sysobjects where id =
object_id('dbo.ProcName') and OBJECTPROPERTY(id, 'IsProcedure') = 1)
crea... more >>
Does SCOPE_IDENTITY() work here?
Posted by Viktor Popov at 7/20/2004 5:37:01 PM
Hi,
What do you thik about this... i have this SP
Create Proc prINSDATA
@param1 varchar(20),
.....
@paramN varchar(p)
AS
insert into table1(n, m, p, q, r) values(@param1, .....,paramN)
Declare @IDENT int
SELECT @IDENT = SCOPE_IDENTITY()
insert into table2(, f,g,y,r)values(.param5,@ID... more >>
Query question
Posted by Sync Walantaji at 7/20/2004 5:34:47 PM
Can some one help me with this?
I can't figure this out....
T1
T1_ID PK
Name
T2
T2_ID PK
T1_ID
Location
T3
T3_ID PK
T2_ID
Building
T4
T4_ID PK
T3_ID
Status
I want to print out a report like this
Name Location Building Count(T4_ID) Count(Status)
===... more >>
DB Chaining Problem
Posted by Scott Meddows at 7/20/2004 5:33:47 PM
When I execute this command:
USE master
EXEC sp_dboption 'Operations', 'db chaining', 'ON'
I receive this error:
Database option 'db chaining' does not exist.
I'm using SQL Standard on a Win 2K Server box.
HELP!!
Thanks
Scott
... more >>
Changing Cross DB Ownership Chaining
Posted by Scott Meddows at 7/20/2004 5:10:34 PM
I'm trying to set up Cross DB Ownership Chaining as per the BOL onto a SQL Standard box.
When I execute this command:
EXEC sp_configure 'Cross DB Ownership Chaining', '0'; RECONFIGURE -- This is from Books Online
I get this message:
The configuration option 'Cross DB Ownership Chaining' do... more >>
if statement with SP in ASP.NET
Posted by Viktor Popov at 7/20/2004 4:59:37 PM
Hi ,
I have the following SP:
CREATE PROCEDURE prSVUSERINFO
@USRNAM VARCHAR(20),
@USRPSW VARCHAR(20),
@NAME VARCHAR(64),
@ADDR VARCHAR(74),
@EML VARCHAR(64),
@ROLE VARCHAR(6),
@RCOUNT INT OUTPUT
AS
IF NOT EXISTS( SELECT * FROM BLEK.USERS A WHERE A.USERNAME=@USRNAM OR
A.USEREMAIL=@EML)
... more >>
Output parameters
Posted by Willie Bodger at 7/20/2004 4:42:05 PM
OK, if I have a sproc which has to return 2 values (a description and a
date) to an ASP page, what is the best way to do that? I was starting with
Output parameters, but then realized I wasn't sure how to call them from the
ASP page that called the sproc. Any examples would be greatly appreciated... more >>
Conditional Inner join
Posted by Star at 7/20/2004 4:26:24 PM
Hi
I know that this cannot be done:
select * from T1
inner join T2 on T1.a = T2.b
OR
inner join T3 on T1.a = T3.b
what I'm trying to do is to get all the records from T1 where either the
first or the second join is true.
I know I could do something like this:
select DISTINCT * fro... more >>
Newbie here, how does subquery work in sql server?
Posted by dfccf at 7/20/2004 3:27:01 PM
I'm fairly experience with sql, but not experienced at all with sql server. I have a problem at work where I have 2 tables. One table I have 3 important fields: one that is a text field (field1), one that is its primary key field (field2) and one that is a primary key of a second table (field3) (... more >>
Store Procedure which should return multi rows but Returns only one Row Always?
Posted by Pandu at 7/20/2004 3:24:47 PM
Hi,
I have Store Procedure which should return multi rows but
Returns only one Row Always?
Can any one point out why it always only one row
--------------------------------------------------
SET QUOTED_IDENTIFIER OFF
-- SET ROWCOUNT 100
GO
SET ANSI_NULLS OFF
GO
ALTER ... more >>
Foramt number -- get rid of trailing 0's in decimal places
Posted by martin at 7/20/2004 2:50:13 PM
Hi,
I am storeing a number as a decimal (18,2) in the database, when I do a
select the number always comes backed "padded" out to 2 decimal places with
0's
for example
10 is 10.00
10.1 is 10.10
is there any way I can make then come back in myselect so that the
additional 0's on the e... more >>
Combining Queries
Posted by Mike Perry at 7/20/2004 1:49:28 PM
OK, I give up, there has to be a simple answer to this but I've dented the
wall banging my head into it trying to figure it out.
The following Query works as expected and the result set is what is desired
(13338 records):
SELECT *
FROM OPENQUERY(wcw, 'SELECT Cust_Nbr,
Order_Nbr,
Ent... more >>
Dynamic SQL question
Posted by John Dude at 7/20/2004 1:24:49 PM
Hi!
I need to build a where clause for my SQL query. Please see the code
below:
create table #Accounts
(ID int,
AccountName varchar(100))
insert into #Accounts values (1, '12345')
insert into #Accounts values (2, '99999')
declare @SQL varchar(100)
declare @where varchar(20)
declar... more >>
unable to return @@identity after insert - please help
Posted by Moe Sizlak at 7/20/2004 1:23:37 PM
Hi There,
I am trying to return the identity of the last inserted record, the output
parameter seems to be null. What am I doing wrong?
Moe
-- page code
myCommand.Parameters.Add(New SqlParameter("@listingID", SqlDbType.Int, 4))
myCommand.Parameters("@listingID").Direction() = Paramet... more >>
Optimizations, Views and Joins
Posted by MaxMax at 7/20/2004 12:40:06 PM
If I make a query that uses a join on a view, will the optimizer create a
single "optimized command" or will it optimize only the query?
example:
mytable is a table, mytableview is a view built on top of mytable,
mybasetable is a standard table:
SELECT * from mybasetable LEFT JOIN mytable ON ... more >>
Error on SP
Posted by Zwi2000 at 7/20/2004 12:32:52 PM
I am running the SP below, the database fields are varchar, still the insert
gives the error below:
I checked the values and its a regular address, nothing out of the ordinary.
------ ERROR ------
Technical Information (for support personnel)
a.. Error Type:
Microsoft VBScript runtim... more >>
Convert folder structure into table
Posted by Terri at 7/20/2004 12:21:18 PM
Any help would be appreciated.
I have a folder structure as follows: a root folder, subfolders from A-Z,
each subfolder A-Z has subfolders that is the name of the client. Each
client folder contains documents associated with the client.
I want to convert this folder structure into a table wi... more >>
OT: Skills assessment test
Posted by Edward at 7/20/2004 12:06:57 PM
Sorry for this non-programming question but I might start
doing some contract work soon. The contractor company is
going to have my skills tested over the phone by someone,
like a third party. I am confident in my ability but
don't actually like tests. Has anyone had this happen to
them... more >>
Need help with query, please
Posted by EManning at 7/20/2004 12:02:18 PM
I've got a table with 4 columns called Dx1, Dx2, Dx3, and Dx4 (all
varchars). I want the query to include the row if only one column has a
value. Below is part of my query so far....is there a way to make it
simpler?
select <snip>...where (Dx1 is not null and Dx2 is null and Dx3 is null... more >>
Long Object Names
Posted by A.M at 7/20/2004 11:36:44 AM
Hi,
I am working on databases and tables with long name and I know that I can
use views to shorten queries.
In Oracle we use synonyms to shorten query typing.
Is there any similar capability in SQL server other than views?
Thanks,
Alan
... more >>
FK to a view?
Posted by Ian Boyd at 7/20/2004 11:22:46 AM
Celko says that you should not prefix tables and views with things such as
(tbl, vw, table, view, etc); becuase that leaks to a user how the data is
stored (a table or view).
So if a table and view should be indisguishable, why can i not create a
foreign key to a view; as i can to a table?
... more >>
db_owner role in SQL 2k
Posted by John at 7/20/2004 11:01:27 AM
I have added a new user in the db_owner role in SQL 2k.
When this user creates a table or any other DB object, it
is owned by the user and not by dbo even though the ID is
a part of DBO. Is this a default behavior in SQL 2k or do
I need to do something different in order for the object
to ... more >>
INSERT Statement
Posted by kalyan at 7/20/2004 10:06:08 AM
Hi
I need a help, Is there anyway to use CASE statement in
Insert command.
Here is example
Table A
Sl.no Value
1 2
2 3
4 NULL
5 3
Insert into table b
select sl_no,
if value null 99 else value
from tab... more >>
Select Two fields as one?
Posted by Lars Netzel at 7/20/2004 9:23:02 AM
I have a table called tbl_Employees with emp_LastName and emp_PrefferredName
fields.
I want to select both those fields into one sorta like
SELECT emp_prefferredName & ' ' & emp_lastName as Fullname FROM tbl_employee
but it does'nt work... I get this error
"Invalid operator for data typ... more >>
Any new analytic SQL Features in SQL2005?
Posted by Leander at 7/20/2004 9:16:50 AM
Common Table Expressions introduced in SQL2005 is realy great thing.
Now I wonder are there plan to add any new analytic SQL features which
Oracle has since 9i version like:
FIRST/LAST
GROUP BY GROUPING SETS
Composite Columns on ROLLUP/CUBE clause
GROUPING, GROUPING_ID and GROUP_ID
MATERIALIZ... more >>
BEGIN TRANS... Where's The Error?
Posted by John at 7/20/2004 9:10:32 AM
After some research and learning about what an UPDLock is
and how it works, I wanted to test it.
I created a table, AAA, comprised one integer
field, "Duh", which is defaulted to zero.
Then I created code which increments "Duh" 10,000 times.
Here is the code:
SET NOCOUNT ON
DECL... more >>
Query Analyzer and XML
Posted by Random at 7/20/2004 8:56:36 AM
I am having trouble viewing XML queried results in Query Analyzer. I've set
it to return 'Results in Text', but the results are still truncated after a
set number of characters. What am I missing?
... more >>
Stored Procedures and Security
Posted by Scott Meddows at 7/20/2004 8:47:17 AM
Okay, another big question (This one is probably more specific to my SQL Server instance :) ). It was always my understanding that
SPs are a great way to wrap up SQL commands without having to give security everywhere in the DB. The problem that I have is that
I cannot only give EXEC permissio... more >>
Bit math in SQL
Posted by Dan Holmes at 7/20/2004 8:38:16 AM
I am planning to use an int datatype as a bitfield (1, 2, 4, 8, ...).
Is this a good idea? I know SQLServer has bit operators (&, |, ~). I
can't think of a better solution.
The promblem is i have an order that can be picked by multiple methods.
I was going to use the column and bitmath ... more >>
Help! trying to attach database to SQL 7.0 desktop version. (Neewbie to DBA)
Posted by august_mck NO[at]SPAM yahoo.com at 7/20/2004 8:07:56 AM
I have the SQL 7.0 MDAC desktop engine running on my desktop. I have
the DbaMGR as my utility.
I have received an email with an .mdf file and I am trying to attach
to my database. This does not seem to work,, do I need the .ldf file
as well?
Further I have another enterprise tool to run que... more >>
Many to Many relationship - Select statement
Posted by hngo01 at 7/20/2004 7:40:20 AM
Hi,
Table1:
PT_ID Pt_LN Pt_FN Address
3 ln1 fn1 123 street
5 ln2 fn2 111 street
8 ln3 fn3 122 street
9 ln4 fn4 1289 street
Table2:
PT_ID Protocol_ID
3 1
3 3
Table3:
Protocol_ID Protocol_Name
1 Name_1
3 Name_3
We have many to many relationships with Table 2:
... more >>
Select Last Row
Posted by Simon at 7/20/2004 6:54:24 AM
Does anyone know how to obtain the last value of a column
in a a resultset? Here is an example of what I am looking
for:
Resultset:
a b c
1 1 1
2 2 2
3 NULL 3
4 NULL NULL
I want to get the last value for a, b, and c so my query
can bring back the following... more >>
SQL:BatchCompleted and RPC:Completed
Posted by googlegroups NO[at]SPAM gawab.com at 7/20/2004 6:07:28 AM
I am executing storedprocedures from C# using SQLClinet.
In the SQL Profiler, I get SQL:BatchCompleted for one of them and
RPC:Completed for another.
Can anyone tell me what SQL:BatchCompleted and RPC:Completed are? and
why i am getting a different results for these two sprocs?
The st... more >>
Query Optimization
Posted by abdul_n_khan NO[at]SPAM hotmail.com at 7/20/2004 5:27:33 AM
I am basic level user have not had much experience with databases
storing large amount of data. I need expert opnion regarding the
optimization of following query.
SELECT distinct table1.fldA, table1.fldB FROM table1
where
table1.fldA in (select table2.fldA from table2)
table1 has aprox ... more >>
New Trigger
Posted by Tony C at 7/20/2004 3:19:23 AM
Help Newsgroup
Is it possible to create a trigger in SQL 7.0, where if a
delete occurs the trigger does nothing, but if an update
occurs then something occurs?
Many Thanks
Tony C... more >>
Error creating clustered index
Posted by Craig HB at 7/20/2004 3:17:01 AM
Hi
I want to created an indexed view, but get an error when I create the error. I want the index to be on both the LocationID and NetSalesAmt columns so it is a materialized view. Here are the details...
<< desired resultset >>
LocationID NetSalesAmt
----------- ---------------------
... more >>
Data Conversion
Posted by Phil at 7/20/2004 2:48:05 AM
Hi All,
I have one field in a table that is currently a ntext field
as it was the only size big enough to put the data in that
I wanted, the problem with the data is it hhas a lot of
java script in it and all I want is the data that is
between the brackets, I need to put each set of data
bet... more >>
adjacency list model
Posted by Henry at 7/20/2004 2:45:41 AM
I have as table created using the adjacency list model
(http://www.intelligententerprise.com/001020/celko.jhtml?_requestid=132953)
and all works well however, I would like to populate a MS Tree control from
the data in the list
(http://support.microsoft.com/default.aspx?scid=kb;en-us;209891)
... more >>
Convert from varchar to numeric
Posted by Indyyan at 7/20/2004 2:35:03 AM
I tried to convert some fields from my table to numeric, but I get a error message.
I used the Enterprise Manager to change form varchar to numeric.
Is there another way to change the datatype??
Greetings Jan... more >>
simple query- dynamic variables
Posted by ab at 7/20/2004 2:12:04 AM
Hello Experts,
How can I pass the owner name (@ownername) dynamically with the system function OBJECT_ID alongwith the name of the object(@tablename)?
I need to do something like (i know this is not correct):
SELECT name FROM sysindexes WHERE id = object_id(@ownername + '.' + @tablename) AN... more >>
Where in msdb can I find Active X Scripts from a DTS package
Posted by Dan NO[at]SPAM Hope_Hospital_Salford_UK at 7/20/2004 2:07:03 AM
Hi
I am trying to recover a DTS package containing an ACtive X Script after my trial version of SQL Server expired.
I was told that the script is held somewhere in the msdb database, after searching through this database I cannot find anything related to my DTS package or Active X Script, can ... more >>
Which is more efficient when finding a record?
Posted by Michael at 7/20/2004 12:42:10 AM
i need to have a query that finds a particular record exists in a table...
was wondering which is more efficient
1. select count(*) as myrecordcount from table1 where field1 = '12345'
2. select * from table1 where field1 = '12345'
in my prog language for query 1, i just have to check if
... more >>
How to make this query ...
Posted by Zwi2000 at 7/20/2004 12:29:10 AM
I have this query:
Select b.caseid, a.userid from atts as a
inner join cases b on a.caseid = b.id
group by b.caseid, a.userid
Results:
Caseid Userid
DEMO0021H 3
DEMO0021H 6
DEMO0021H 7
DEMO0021H 8
H1b-34234 ... more >>
Data Fix
Posted by Phil at 7/20/2004 12:17:39 AM
Hi All,
I have one field in a table that is currently a ntext field
as it was the only size big enough to put the data in that
I wanted, the problem with the data is it hhas a lot of
java script in it and all I want is the data that is
between the brackets, I need to put each set of data
bet... more >>
|