How to exclude a field during a select query?

Updated on technology 2024-05-23
7 answers
  1. Anonymous users2024-02-11

    If it is sqlserver, all table names and all column names are stored in it, and you can query it by using the following statement:

    declare @columnlist varchar(8000), tablename varchar(255) - Defines two variables.

    select @columnlist = ' ', @tablename= 'The name of the table to be queried'--Variable assignment.

    select @columnlist=@columnlist+name+ ', ' from where object_id = object_id(@tablename) and name<>'The list name to be culled'--Loop through all the columns you need for the query (minus the ones you don't want).

    select @columnlist=left(@columnlist,len(@columnlist)-1) - Remove the last ',' sign in the constructed statement.

    exec( 'select '+@columnlist+ ' from '+@tablename) - Executes dynamic statements.

    Try.

  2. Anonymous users2024-02-10

    1. Create a test table, here we take creating 6 fields as an example, if there are 100 fields, the operation is similar, create table test sel cols(id number, password varchar2(200), remark1 varchar2(100), remark2 varchar2(100), remark3 varchar2(100), remark4 varchar2(100));

    2. View the table structure through the system view; You can see all the fields of the newly created table;

    select * from user_tab_cols t where table_name = test_sel_cols';

    3. Write SQL to get all the fields with password removed from the view;

    select 'select '|listagg(column_name, 'within group(order by column_id) |from test_sel_cols'知芹 str from user tab cols t where table name = test sel cols'and column name <> Li Sen'password'Completion of the disturbance;

    4. Copy the query result from the previous step to generate the required SQL as follows:

    select id, remark1, remark2, remark3, remark4 from test_sel_cols

    It can be found that the password field is missing;

  3. Anonymous users2024-02-09

    1. Create a test table, here we take creating 6 fields as an example, if there are 100 fields, the operation is similar, create table test sel cols(id number, password varchar2(200), remark1 varchar2(100), remark2 varchar2(100), remark3 varchar2(100), remark4 varchar2(100));

    2. View the table structure through the system view; You can see all the fields of the newly created table;

    select * from user_tab_cols t where table_name = 'test_sel_cols';

    3. Write SQL to get all the fields with password removed from the view;

    select 'select '||listagg(column_name, ',') within group(order by column_id) |' from test_sel_cols' str from user_tab_cols t where table_name = 'test_sel_cols' and column_name <>'password';

    4. Copy the query result from the previous step to generate the required SQL as follows:

    select id, remark1, remark2, remark3, remark4 from test_sel_cols

    It can be found that the password field is missing;

  4. Anonymous users2024-02-08

    If you want to write it in one sentence, you have to list all 99 fields one by one.

    But you can use dynamic statements to get lazy.

    declare @cols as varchar(4000)

    select @cols = isnull(@cols,'') +name +',' from syscolumns s

    where 1=1 and id = (select id from sysobjects where name ='yourtable') -and name <>'Fill in the fields you exclude here'

    set @cols = left(@cols,len(@cols)-1 )

    exec ('select ' + cols + ' from yourtable')

    Note: This is tsql**, only for mssql

  5. Anonymous users2024-02-07

    The way you want this is not there, and there are only two cases of a query list for a query statement

    from [tablename] - Query all columns.

    a, b, c from [tablename] - Query the specified columns.

  6. Anonymous users2024-02-06

    Didn't get what you mean.

    Can't you query the information in the table directly?

    select

    from user_col_commentswhere table_name = upper( 'The name of a table');

  7. Anonymous users2024-02-05

    It should be the only way.

Related questions
2 answers2024-05-23

Too much lead can cause a child to have low intelligence, lower academic performance, develop ADHD, lack of concentration, and be impulsive and willful. >>>More

3 answers2024-05-23

I, you, have hope.

First of all, you want the company's products, and the payment to the personal account, is not normal, why not the company account? >>>More

5 answers2024-05-23

What tests should be done to rule out kidney disease? Therefore, renal insufficiency is generally a manifestation of advanced kidney disease, and normal renal function does not exclude the possibility of nephritis. If it is true that the kidneys are damaged, it is necessary to supplement high-quality animal protein, and it is best to eat fish when eating meat.

7 answers2024-05-23

Some convenient and fast patent query ** or patent query platform are as follows: 1. The platform of the State Intellectual Property Office 2. The patent query platform of Wisdom Buds 3. The Wisdom Buds patent inquiry platform provides a one-stop information service platform for patent retrieval, analysis and management, and the company is committed to letting more organizations and institutions around the world understand and use patents more efficiently 4. The State Intellectual Property Office of China is the most directly subordinate agency in charge of patent work and the overall coordination of foreign-related intellectual property matters. It has intellectual property affairs such as patent application, patent examination, patent protection, patent**, PCT, integrated circuits, document services, important news, laws and regulations, and international cooperation. >>>More

14 answers2024-05-23

What is the reason for the difference between the official seal and the words on it?